refactoring out some duplication