Apply refactoring for the function