fix bug on exit