Fix panic on out-of-bounds array access