Refactor to remove duplication