fixed a bug on exit