Move the code for generating copies into a common place.