First phase of making SORT CASES stable (PR 12035).