fixed some segmentation faults