Converting to use new statistics api. Improving code for downloading csv.