Refactoring to simplify logic.