Fix bug of segmentation fault