Fix and test sort