small refactoring of if/logic