Bug fixing

added shared pointers and fixed destructor bugs (missing "virtual")