Partly fixed segmentation fault