fix a bug when reverse sorting is set