Moving some sorting related stuff to it's own utils file