fix a bug that index out of range