Implement total sort.