Fix csv writing