fixed a bug that could crash the core on exit