Add second to-csv function. Needs refactoring