Fixed bugs with CSV generation