split out common rest code