Factor out a common procedure.