Fixed some sorting bugs.