fix array index out of bound exception