diff --git a/src/workflow.py b/src/workflow.py
index 612bd0e337a222a28db46c1c440f8b3dcba73a2b..e21542b6419e694cddf74d9cc290162745fb45e6 100644
--- a/src/workflow.py
+++ b/src/workflow.py
@@ -328,6 +328,15 @@ George Marchment, Bryan Brancotte, Marie Schmit, Frédéric Lemoine, Sarah Cohen
             nextflow_file = self.get_first_file()
 
             code = nextflow_file.get_code()
+
+            #Move the workflow.complete to end of the workflow if it's not already done
+            for match in re.finditer(r"workflow\.onComplete\s*{", code):
+                start = match.span(0)[0]
+                end = extract_curly(code, match.span(0)[1])#This function is defined in the functions file
+                workflow_on_complete = code[start:end]
+                code = code.replace(workflow_on_complete, "")
+                code+="\n"*2+workflow_on_complete
+
             start_code = r"#!/usr/bin/env nextflow"
             start_code_pattern = r"\#\!\s*\/usr\/bin\/env\s+nextflow"
             end_code = "workflow.onComplete"
@@ -340,14 +349,13 @@ George Marchment, Bryan Brancotte, Marie Schmit, Frédéric Lemoine, Sarah Cohen
                 pos_start = match.span(0)[1]+1
             #if(code.find(start_code)!=-1):
             #    pos_start = code.find(start_code)+len(start_code)
-            body = code[pos_start:pos_end]#.replace('\n', '\n\t')
+            body = code[pos_start:pos_end].strip()#.replace('\n', '\n\t')
 
             include_section = f"//INCLUDE_SECTION_{tag}"
             params_section = f"//PARAMS_SECTION_{tag}"
             function_section = f"//FUNCTION_SECTION_{tag}"
             process_section = f"//PROCESS_SECTION_{tag}"
 
-
             code = code.replace(code_to_replace, f"""{start_code}\n\n\n{include_section}\n\n\n{params_section}\n\n\n{function_section}\n\n\n{process_section}\n\n\nworkflow{{\n\n{body}\n}}\n\n""")
 
             ##I've out this in a comment cause since it's a DSL1 
@@ -1632,8 +1640,6 @@ George Marchment, Bryan Brancotte, Marie Schmit, Frédéric Lemoine, Sarah Cohen
                         pattern= fr"[\s\(,]({re.escape(old)})[^\w]"
                         temp = code
                         code = replace_group1(code, pattern, new)
-                        if(temp==code and old!=new):
-                            raise Exception("The old wasn't update")
                         #code = code.replace(old, new)
 
                     #Since i've added the conditions myself -> i can just count them by searching for this simple pattern