Refactor if statement