diff --git a/count_matrix.py b/count_matrix.py
index ea3a94ee9f13297f0f5a9414a4e3b29944a366a7..c0651ed9ab2c2a65ad49eb1a1319f8edc5dc5b74 100755
--- a/count_matrix.py
+++ b/count_matrix.py
@@ -25,14 +25,10 @@ import re
 import os.path
 import glob
 
-#----------------------------- DICTIONNARIES ----------------------------------#
-
-MATRIX = {}
-COUNT = {}
 
 #-------------------------- FUNCTIONS DEFINITION ------------------------------#
 
-def read(filename, nb_samples, id_sample):
+def read(filename, nb_samples, id_sample, MATRIX,COUNT):
     """
     Function that read a count table 
 
@@ -59,11 +55,12 @@ def read(filename, nb_samples, id_sample):
                 MATRIX[ref] = size
                 COUNT[ref] = ['0'] * nb_samples
             # get number of mapped reads and add to count table
-            count = columns[2]
-            COUNT[ref][id_sample] = count
+            data = columns[2]
+            COUNT[ref][id_sample] = data
+    return MATRIX, COUNT
 
 
-def write(output):
+def write(output, MATRIX, COUNT):
     """
     Function that write the count matrix
 
@@ -122,17 +119,19 @@ if __name__ == '__main__' :
     # merging files
     filenames=[]  # label list of samples, with the extension '.txt'
     nb_tables = len(files) # total number of file to merge
+    MATRIX = {}
+    COUNT = {}
 
-    for i in xrange(nb_tables):
+    for i in range(nb_tables):
         # get sample name
         table = files[i]
         base=os.path.basename(table)
         filenames.append(base[:-4])
         # get information from the table
-        read(table, nb_tables, i) 
+        read(table, nb_tables, i, MATRIX, COUNT) 
 
     # write the count matrix
     output = os.path.abspath(arguments['output']) # file name
-    write(output) 
+    write(output, MATRIX, COUNT)