Add CSV export code for #666