pull out common code