fix array out of bound issue