Move common code out