function refactoring