Refactored out some duplication