fixed crash bug on exit