Fix pre-sorting so it actually works