fixed crashing on exit