Fixed the segmentation fault
The sorting still doesn't work correctly though