Fix bug on exit