refactoring conditional branch