updated to flush csv file