refactoring to use the factory