Fixes to the csv writer funtion