Refactoring if statements