fixed some comments, and write csv.gz
more organised version, plus locally homogeneous handling