fix array out of bounds access