diff --git a/src/root.py b/src/root.py
index 3292fdc937f4a982e7747d4e767a4e28154ca887..250ec9ff39b8033556da8efa17de71e598204039 100644
--- a/src/root.py
+++ b/src/root.py
@@ -227,23 +227,35 @@ class Root(Nextflow_Building_Blocks):
 
         self.extract_executors()
 
-        #TODO i need to sort the execution order out
+        #This is to get the order of execution
+        code = self.get_code()
         position_2_thing_2_analyse = {}
         for block in self.blocks:
-            pos = code.find(block.get_code())
-            if(pos!=-1):
-                position_2_thing_2_analyse[pos] = block
-                code = code.replace(block.get_code(), "a"*len(block.get_code()), 1)
-            else:
+            block_code = block.get_code()
+            found = False
+            while(not found or len(block_code)==0):
+                pos = code.find(block_code)
+                if(pos!=-1):
+                    position_2_thing_2_analyse[pos] = block
+                    code = code.replace(block_code, "a"*len(block_code), 1)
+                    found = True
+                else:
+                    block_code = block_code[:-1]
+            if(not found):
                 raise Exception("This shouldn't happen")
         for e in self.executors:
-            pos = code.find(e.get_code())
-            if(pos!=-1):
-                position_2_thing_2_analyse[pos] = e
-                code = code.replace(e.get_code(), "a"*len(e.get_code()))
-            else:
-                raise Exception("This shouldn't happen")
-            
+            e_code = e.get_code()
+            found = False
+            while(not found or len(e_code)==0):
+                pos = code.find(e_code)
+                if(pos!=-1):
+                    position_2_thing_2_analyse[pos] = e
+                    code = code.replace(e_code, "a"*len(e_code), 1)
+                    found = True
+                else:
+                    e_code = e_code[:-1]
+            if(not found):
+                raise Exception("This shouldn't happen")            
         sorted_position_2_thing_2_analyse = dict(sorted(position_2_thing_2_analyse.items()))
 
         for key in sorted_position_2_thing_2_analyse: