This hopefully fixes the occasional segfault when exiting the core.