refactored the factory