Moved coded used in all cpp files to misc.h and modified cpp files
Refactoring