Refactored to a single if statement