Fixed a non-virtual destructor and added a few checks.