fix bug with array index