Fixed the array access beyond bounds.