Refactored to make repository the factory