refactor if else statement