fix array out of bounds error.