Sort optimisation
Merge pull request #1196 from jpeg729/optimisation

Sort optimisation