fixing a bug in core.cpp (yet another crash on exit)