minor restructure to remove duplicate code