Bugfix: sort more efficiently