Finished unifing sort functions