diff --git a/cal_tools/cal_tools/agipdlib.py b/cal_tools/cal_tools/agipdlib.py
index 5ac64e76d2636a50f9326dddaf6b9112283e99a1..fc5412fb0bfe46b8d1650da80617d70822ec9bc2 100644
--- a/cal_tools/cal_tools/agipdlib.py
+++ b/cal_tools/cal_tools/agipdlib.py
@@ -91,8 +91,8 @@ class AgipdCorrections:
         :param max_cell: maximum number of memory cells to handle, e.g. if
                          calibration constants only exist for a subset of cells
         :param channel: module/channel to correct
-        :param max_pulses: pulse indices to consider for preview histograms
-        :param rng_pulse_idx: maximum pulse idx to consider for preview histograms
+        :param max_pulses: maximum pulse indices to consider for preview histograms
+        :param rng_pulse_idx: range of pulse indices to consider for preview histograms
         :param bins_gain_vs_signal: number of bins for gain vs signal histogram
         :param bins_signal_low_range: number of bins for the low signal
             range histogram
@@ -1029,20 +1029,25 @@ class AgipdCorrections:
         if self.melt_snow is not False:
             msk |= snowmask
 
+        agipd_base = self.agipd_base
+        allpulses = np.squeeze(self.infile[agipd_base + "image/pulseId"])
+
         # for the first chunk output some statistics
         if cidx == 0:
             copim = copy.copy(im)
             copim[copim < self.median_noise] = np.nan
-            bins = (self.bins_signal_low_range, self.rng_pulse_idx)
-            rnge = [[-50, 1000], [self.max_pulses[0], self.max_pulses[-1]]]
+            bins = (self.bins_signal_low_range, self.max_pulses)
+            rnge = [[-50, 1000], [allpulses[self.rng_pulse_idx[0]],
+                                  allpulses[self.rng_pulse_idx[-1]]]]
             H, xe, ye = np.histogram2d(np.nanmean(copim, axis=(1, 2)),
                                        pulseId,
                                        bins=bins,
                                        range=rnge)
             self.hists_signal_low += H
             self.low_edges = (xe, ye)
-            bins = (self.bins_signal_high_range, self.rng_pulse_idx)
-            rnge = [[0, 200000], [self.max_pulses[0], self.max_pulses[-1]]]
+            bins = (self.bins_signal_high_range, self.max_pulses)
+            rnge = [[0, 200000], [allpulses[self.rng_pulse_idx[0]],
+                                  allpulses[self.rng_pulse_idx[-1]]]]
             H, xe, ye = np.histogram2d(np.nanmean(copim, axis=(1, 2)),
                                        pulseId,
                                        bins=bins,
@@ -1161,7 +1166,7 @@ class AgipdCorrections:
 
 
         can_calibrate = (allcells < max_cells)
-        can_calibrate &= (allpulses < np.max(allpulses[np.array(self.max_pulses)]))
+        can_calibrate &= (allpulses < np.max(allpulses[np.array(self.rng_pulse_idx)]))
         
         if np.count_nonzero(can_calibrate) == 0:
             return
diff --git a/notebooks/AGIPD/AGIPD_Correct_and_Verify.ipynb b/notebooks/AGIPD/AGIPD_Correct_and_Verify.ipynb
index 59971159399109e659f8cae05001d086fd5b289e..05f46a010bc4686fbf99b1fe5b96d2a2a3c3cb65 100644
--- a/notebooks/AGIPD/AGIPD_Correct_and_Verify.ipynb
+++ b/notebooks/AGIPD/AGIPD_Correct_and_Verify.ipynb
@@ -502,39 +502,31 @@
     "inp = []\n",
     "left = total_sequences\n",
     "\n",
-    "# check if max_pulses is a list, tuple or int.\n",
-    "# if list, then it's content are the requested pulse indices.\n",
-    "# if tuple, then it is a definition for a range of pulse indices.\n",
-    "# if int, then it is the max pulse indices starting 0.\n",
-    "\n",
-    "print(type(max_pulses))\n",
-    "if isinstance(max_pulses, list):\n",
-    "    if len(max_pulses) == 3:\n",
-    "        max_pulses = list(range(max_pulses[0],\n",
-    "                                max_pulses[1],\n",
-    "                                max_pulses[2]))\n",
-    "    elif len(max_pulses) == 2:\n",
-    "        max_pulses = list(range(max_pulses[0],\n",
-    "                                max_pulses[1],\n",
-    "                                1))\n",
-    "    elif len(max_pulses) == 1:\n",
-    "        rng_pulse_idx = max_pulses[0]\n",
-    "        max_pulses = list(range(max_pulses[0]))\n",
+    "# Checking the max_pulses input\n",
+    "# Applying default values if input not 3 elements.\n",
+    "if len(max_pulses) == 3:\n",
+    "    rng_pulse_idx = list(range(max_pulses[0],\n",
+    "                            max_pulses[1],\n",
+    "                            max_pulses[2]))\n",
+    "    max_pulses = len(rng_pulse_idx)\n",
+    "elif len(max_pulses) == 2:\n",
+    "    rng_pulse_idx = list(range(max_pulses[0],\n",
+    "                            max_pulses[1],\n",
+    "                            1))\n",
+    "    max_pulses = len(rng_pulse_idx)\n",
+    "elif len(max_pulses) == 1:\n",
+    "    rng_pulse_idx = list(range(max_pulses[0]))\n",
+    "    max_pulses = max_pulses[0]\n",
+    "else:\n",
+    "    raise ValueError(\"Wrong input for max_pulses {} \\n\".format(max_pulses),\n",
+    "                     \"max_pulses should have 3 arguments maximum\")\n",
     "\n",
-    "    else:\n",
-    "        raise ValueError(\"Wrong input for max_pulses {} \\n\".format(max_pulses),\n",
-    "                         \"max_pulses tuple has more than 3 arguments\")\n",
-    "    rng_pulse_idx = len(max_pulses)\n",
-    "elif isinstance(max_pulses, int):\n",
-    "    rng_pulse_idx = max_pulses\n",
-    "    max_pulses = list(range(max_pulses))\n",
-    "    \n",
     "bins_gain_vs_signal = (100, 100)\n",
     "bins_signal_low_range = 100\n",
     "bins_signal_high_range = 100\n",
     "bins_dig_gain_vs_signal = (100, 4)\n",
-    "hists_signal_low =  np.zeros((bins_signal_low_range, rng_pulse_idx), np.float64)\n",
-    "hists_signal_high =  np.zeros((bins_signal_low_range, rng_pulse_idx), np.float64)\n",
+    "hists_signal_low =  np.zeros((bins_signal_low_range, max_pulses), np.float64)\n",
+    "hists_signal_high =  np.zeros((bins_signal_low_range, max_pulses), np.float64)\n",
     "hists_gain_vs_signal =  np.zeros((bins_gain_vs_signal), np.float64)\n",
     "hists_dig_gain_vs_signal =  np.zeros((bins_dig_gain_vs_signal), np.float64)\n",
     "gain_stats = 0\n",