Add explicit destructor and fix a memory leak