fixed segmentation fault at the end