refactoring into multiple functions