fix an index out of bound exception