refactoring to return object of the factory