changed to factory pattern