fix some bugs for sort