Refactored to use the factory class