fix index out of bound