Updated to efficiently write csvs