Fix a bug when index is set