adding a number of null and undefined checks - being uncovered as previous fixes make code move forward to find new bugs