Some function refactoring