Fixed segmentation fault bug