Fix sort logic.