Think this works. Segmentation faults so preparing for a merge