Convert repeated code into function calls.