Implemented destructor to free resources.