Extracting repeated code to a function.