Refactoring with helper functions