fixed some crashes while shutting down