diff --git a/PyNutil/coordinate_extraction.py b/PyNutil/coordinate_extraction.py
index fecb68fc7741bbb3c2aed35fada36b1396c50dcc..1edb063f6406a5154362ce6fbec85da9edcb1974 100644
--- a/PyNutil/coordinate_extraction.py
+++ b/PyNutil/coordinate_extraction.py
@@ -273,7 +273,7 @@ def labelPoints(points, label_volume, scale_factor=1):
 
 # related to object_counting
 # consider separating out writing to CSV in future
-def PixelCountPerRegion(labelsDict, label_colours, output_csv): 
+def PixelCountPerRegion(labelsDict, label_colours): 
     """Function for counting no. of pixels per region and writing to CSV based on 
     a dictionary with the region as the key and the points as the value, """
     counted_labels, label_counts = np.unique(labelsDict, return_counts=True)
@@ -305,6 +305,9 @@ def PixelCountPerRegion(labelsDict, label_colours, output_csv):
         new_rows.append(row)
 
     df_counts_per_label_name = pd.DataFrame(new_rows)
+    return df_counts_per_label_name
     
-    df_counts_per_label_name.to_csv(output_csv, sep=";", na_rep='', index= False)
+   
+#def SaveDataframeasCSV(df_to_save):
+    #df_to_save.to_csv(output_csv, sep=";", na_rep='', index= False)
 
diff --git a/PyNutil/folder_of_segmentations_to_meshview_multithreaded.py b/PyNutil/folder_of_segmentations_to_meshview_multithreaded.py
index 001cc7d82ae40d03f56421749906fa46c2c9b135..7c1d6955dc25ec06ea38a49c5b02d5497ea1ff28 100644
--- a/PyNutil/folder_of_segmentations_to_meshview_multithreaded.py
+++ b/PyNutil/folder_of_segmentations_to_meshview_multithreaded.py
@@ -16,7 +16,7 @@ with open('../test/test2.json', 'r') as f:
 
 #import our function for converting a folder of segmentations to points
 from coordinate_extraction import FolderToAtlasSpace, labelPoints, WritePointsToMeshview, FolderToAtlasSpaceMultiThreaded, PixelCountPerRegion
-#from read_and_write import WritePointsToMeshview
+from read_and_write import SaveDataframeasCSV
 
 startTime = datetime.now()
 
@@ -37,7 +37,9 @@ labels = labelPoints(points, data, scale_factor=2.5)
 #save points to a meshview json
 WritePointsToMeshview(points, labels, input["points_json_path"], label_df)
 
-PixelCountPerRegion(labels, input["allen_colours"], input["counts_per_label_name"])
+df_counts_per_label_name = PixelCountPerRegion(labels, input["allen_colours"])
+
+SaveDataframeasCSV(df_counts_per_label_name, input["counts_per_label_name"])
 
 #while we havent added it here it would be good to next quantify the number of cells for each label.
 
diff --git a/PyNutil/read_and_write.py b/PyNutil/read_and_write.py
index 205de7a2d5961de0bd71136bf285e9cde981a7ad..e791c785058219ba42a82901501be775f4743015 100644
--- a/PyNutil/read_and_write.py
+++ b/PyNutil/read_and_write.py
@@ -1,5 +1,6 @@
 import json
 
+
 #related to read and write: loadVisuAlignJson
 def loadVisuAlignJson(filename):
     with open(filename) as f:
@@ -34,4 +35,9 @@ def WritePoints(pointsDict, filename, infoFile):
 def WritePointsToMeshview(points, pointNames, filename, infoFile):
     """this is the function you call more often as it combines the other functions for writing meshview"""
     regionDict = createRegionDict(points, pointNames)
-    WritePoints(regionDict, filename, infoFile)
\ No newline at end of file
+    WritePoints(regionDict, filename, infoFile)
+
+
+def SaveDataframeasCSV(df_to_save, output_csv):
+    """Function for saving a df as a CSV file"""
+    df_to_save.to_csv(output_csv, sep=";", na_rep='', index= False)
\ No newline at end of file