Function refactoring