move common functionality to helper code