Added functionality to generate and download the CSV file