Fix for possible crash on exit