Improve conditional logic