diff --git a/bin/hicstuff_build_matrix.py b/bin/hicstuff_build_matrix.py
index bd68ee0f5c6a7b839ee4537240019e0147cbb080..194a9d395964a37a5349b7fd7052d5fb0a93af12 100755
--- a/bin/hicstuff_build_matrix.py
+++ b/bin/hicstuff_build_matrix.py
@@ -63,13 +63,17 @@ def pairs2matrix(
             )
 
     pre_mat_file = mat_file + ".pre.pairs"
-    hio.sort_pairs(
-        pairs_file,
-        pre_mat_file,
-        keys=["frag1", "frag2"],
-        threads=threads,
-        tmp_dir=tmp_dir,
-    )
+    # hio.sort_pairs(
+    #     pairs_file,
+    #     pre_mat_file,
+    #     keys=["frag1", "frag2"],
+    #     threads=threads,
+    #     tmp_dir=tmp_dir,
+    # )
+
+    cmd = 'grep -v ^# %s | sort -S 2G -k8,8n -k9,9n --parallel=1' % pairs_file
+    os.system(cmd '>>' prem_mat_file)
+
     header_size = len(hio.get_pairs_header(pre_mat_file))
     with open(pre_mat_file, "r") as pairs, open(mat_file, "w") as mat:
         # Skip header lines