fixed crashes on shutdown