fixed segmentation fault after closing