Refactored to remove duplication