sort matrix entries, this time for real