bugfix on exit