Fixed bugs in factory class