Fixed null reference error in CSV generation