Fixed some errors in the factory cpp