fixed factory bugs