Drop in a bunch of sorting stuff from the old CS3 final