refactor to remove duplication