Fix index out of bound.