I found a bug as described here, I tracked it to this line and added a check to see if it was defined. Tested locally on my Z2M and it has fixed my issue.