refactored out some duplications