fixed some crash on exit bugs