fix sorting bugs.