Fix array access bug