Refactor if condition control