Fixing the segmentation fault