fixed bug in generating csv file