Revert "Revert "better sorting""

This reverts commit 6fb07ade421e17ed81cb3ee506d5b5d22be3a2f3.