Improved crashing/freezing bug on exit/restart