You're checking for undefined twice here.