fix array out of index error