diff --git a/encoder.py b/encoder.py
index 437f3c14238a802473d5d25f220b88a7249e2aa7..8f337023a67e211e21aead32bfbb04be3e67c0e0 100644
--- a/encoder.py
+++ b/encoder.py
@@ -516,7 +516,6 @@ class EncoderAlgorithm(IAMAPAlgorithm):
         ## will update if process is canceled by the user
         self.all_encoding_done = True
 
-        merged_files_counter = 0
 
         for current, sample in enumerate(dataloader):
             if current <= last_batch_done:
@@ -619,8 +618,7 @@ class EncoderAlgorithm(IAMAPAlgorithm):
                 ]
                 all_tiles = [f for f in all_tiles if not f.startswith("merged")]
 
-                dst_path = Path(os.path.join(self.output_subdir, f"{merged_files_counter}_merged_tmp.tif"))
-                merged_files_counter += 1
+                dst_path = Path(os.path.join(self.output_subdir, f"{current}_merged_tmp.tif"))
 
                 try:
                     merge_tiles(