refactored if statement