Refactored if/else order