fixed segmentation fault at exit