modified factory.cpp and factory.h