fix a bug in toinds.py, add a sort.