Pull out common code.