fixing bug in saving the csv