Fixes crash on exit