Fixed overstepping array boundaries bug