diff --git a/pyfstat/helper_functions.py b/pyfstat/helper_functions.py
index 915ba6f3c83bc5a82ebf6622058d5dd04c20e607..80c023d8bc06ef52f606f77d1697438f6cfd5189 100644
--- a/pyfstat/helper_functions.py
+++ b/pyfstat/helper_functions.py
@@ -369,3 +369,16 @@ def twoFDMoffThreshold(
         return twoFDMoffthreshold_below_threshold
     else:
         return 10 ** (prefactor * np.log10(twoFon - offset))
+
+
+def match_commandlines(cl1, cl2, be_strict_about_full_executable_path=False):
+    """ Check if two commandlines match element-by-element, regardless of order """
+    cl1s = cl1.split(" ")
+    cl2s = cl2.split(" ")
+    # first item will be the executable name
+    # by default be generous here and do not worry about full paths
+    if not be_strict_about_full_executable_path:
+        cl1s[0] = os.path.basename(cl1s[0])
+        cl2s[0] = os.path.basename(cl2s[0])
+    unmatched = np.setxor1d(cl1s,cl2s)
+    return len(unmatched)==0
diff --git a/pyfstat/make_sfts.py b/pyfstat/make_sfts.py
index 9ad3149d6449c7a924789aa0d4c389c76c3b5988..4a7dca9769add1f8988f9558c745201935df968a 100644
--- a/pyfstat/make_sfts.py
+++ b/pyfstat/make_sfts.py
@@ -281,15 +281,23 @@ transientTau = {:10.0f}\n"""
                 self.config_file_name, self.sftfilepath
             )
         )
-        logging.info("Checking contents of cff file")
+        #logging.info("Checking contents of cff file") # FIXME: check doesn't seem to exist...?
+        #if not XXX:
+            #logging.info("Contents unmatched")
+            #return False
+        logging.info("Checking commandline against existing SFT header")
         cl_dump = "lalapps_SFTdumpheader {} | head -n 20".format(self.sftfilepath)
         output = helper_functions.run_commandline(cl_dump)
-        found = [True for line in output.split("\n") if line[-len(cl_mfd) :] == cl_mfd]
-        if any(found):
-            logging.info("Contents matched, use old sft file")
+        header_lines_lalapps = [line for line in output.split("\n") if "lalapps" in line]
+        if len(header_lines_lalapps)==0:
+            logging.info("Could not obtain comparison commandline from old SFT header")
+            return False
+        cl_old = header_lines_lalapps[0]
+        if helper_functions.match_commandlines(cl_old,cl_mfd):
+            logging.info("Commandline matched with old SFT header, use old sft file")
             return True
         else:
-            logging.info("Contents unmatched, create new sft file")
+            logging.info("Commandlines unmatched, create new sft file")
             return False
 
     def check_if_cff_file_needs_rewritting(self, content):
@@ -358,8 +366,8 @@ transientTau = {:10.0f}\n"""
             cl_mfd.append('--ephemSun="{}"'.format(sun_ephem))
 
         cl_mfd = " ".join(cl_mfd)
-
-        if self.check_cached_data_okay_to_use(cl_mfd) is False:
+        check_ok = self.check_cached_data_okay_to_use(cl_mfd)
+        if check_ok is False:
             helper_functions.run_commandline(cl_mfd)
 
     def predict_fstat(self):