added function to save to csv file