fixes for potential segmentation faults