refactor if/else