edits to fix segmentation faults