Fixed the segmentation fault