Modified sorting strategy (fixes #10)