Refactoring if cases