Implemented destructor, fixed memory leaks