Refactoring function definitions to avoid using anonymous function