fixed segfault on exit