refactored out some common/shared code