diff --git a/cal_tools/cal_tools/agipdlib.py b/cal_tools/cal_tools/agipdlib.py
index 182a1e616df2af6e885ed6b2c05a620d8e8a111b..2c2de40f86486c5cdc165e91332680675cde0705 100644
--- a/cal_tools/cal_tools/agipdlib.py
+++ b/cal_tools/cal_tools/agipdlib.py
@@ -1285,13 +1285,16 @@ class AgipdCorrections:
             # fidxv: INDEX/.../image/first idx values
             # cntsv: INDEX/.../image/counts values
 
+            # Extract parameters through identifying
+            # unique trains, index and numbers.
             uq, fidxv, cntsv = np.unique(alltrains[firange - firange[0]],
                                          return_index=True,
                                          return_counts=True)
 
-            # Validate calculated CORR INDEX contents
+            # Validate calculated CORR INDEX contents.
             train_diff = np.isin(np.array(self.infile["/INDEX/trainId"]), uq, invert=True)
 
+            # Insert zeros for missing trains.
             for i, diff in enumerate(train_diff):
                 if diff:
                     if i < len(cntsv):
@@ -1301,27 +1304,16 @@ class AgipdCorrections:
                         cntsv = np.append(cntsv, 0)
                         fidxv = np.append(fidxv, 0)
 
-            mv = len(fidxv)
-            fidx = np.zeros(len(fidxv), fidxv.dtype)
-            fidx[self.valid[:mv]] = np.array(fidxv)[self.valid[:mv]]
-
-            for i in range(len(fidx) - 1, 2, -1):
-                if fidx[i - 1] == 0 and fidx[i] != 0:
-                    fidx[i - 1] = fidx[i]
-
-            cnts = np.zeros(len(fidxv), cntsv.dtype)
-            cnts[self.valid[:mv]] = np.array(cntsv)[self.valid[:mv]]
-
-            # add INDEX contents in CORR files
+            # save INDEX contents (first, count) in CORR files
             self.outfile.create_dataset(idx_base + "{}/first".format(do),
-                                        fidx.shape,
-                                        dtype=fidx.dtype,
-                                        data=fidx,
+                                        fidxv.shape,
+                                        dtype=fidxv.dtype,
+                                        data=fidxv,
                                         fletcher32=True)
             self.outfile.create_dataset(idx_base + "{}/count".format(do),
-                                        cnts.shape,
-                                        dtype=cnts.dtype,
-                                        data=cnts,
+                                        cntsv.shape,
+                                        dtype=cntsv.dtype,
+                                        data=cntsv,
                                         fletcher32=True)
 
     def create_output_datasets(self):