refactoring of a function