Refactor conditional logic