Refactor if conditional