Fixed segmentation faults