Fixed some logic errors in the sort, its now late and stuff bye