fixed some memory leaks , updated to c++11