modified the factory to use the provided return type