split off common code