extracted some shared code