Added the code for the factory and singleton