bug fix on exit