split out common functions