fix array access errors