fixing errors in writecsv