replacing repeating code blocks with function calls