Fix csv generation code