Refactor to save some duplication.