update to use the factory pattern