fixed segmentation fault on exit