null checks were not right. Need to check for undefined