fixing segmentation fault