added new csv writing code