Extracting repeated operations to methods