Extract duplicate code to a function.