Fixed crashes for exit