Fixed bug with array boundaries