split out shared code