Modified the service as a factory method