pulled out common code