consolidate shared function