Refactored a service into a factory