Segmentation fault fix