Fix out of bounds array access