improve check for undefined