diff --git a/notebooks/AGIPD/Characterize_AGIPD_Gain_Darks_NBC.ipynb b/notebooks/AGIPD/Characterize_AGIPD_Gain_Darks_NBC.ipynb
index 3397ba745fd4cf5db416ca4742908443cf744b46..8aee1ac01698ad49dfa214d937779f92acb06c16 100644
--- a/notebooks/AGIPD/Characterize_AGIPD_Gain_Darks_NBC.ipynb
+++ b/notebooks/AGIPD/Characterize_AGIPD_Gain_Darks_NBC.ipynb
@@ -211,7 +211,7 @@
     "                gsettings.append(get_gain_setting(control_fname, h5path_ctrl))\n",
     "            if not all(g == gsettings[0] for g in gsettings):\n",
     "                raise ValueError(f\"Different gain settings for the 3 input runs {gsettings}\")\n",
-    "            gain_setting =  gsettings[0]\n",
+    "            gain_setting = gsettings[0]\n",
     "        except Exception as e:\n",
     "            print(f'Error while reading gain setting from: \\n{control_fname}')\n",
     "            print(f'Error: {e}')\n",
@@ -245,7 +245,7 @@
     "print(\"Parameters are:\")\n",
     "print(f\"Proposal: {prop}\")\n",
     "print(f\"Memory cells: {mem_cells}/{max_cells}\")\n",
-    "print(\"Runs: {}\".format([ v for v in offset_runs.values()]))\n",
+    "print(\"Runs: {}\".format([v for v in offset_runs.values()]))\n",
     "print(f\"Sequences: {sequences}\")\n",
     "print(f\"Interlaced mode: {interlaced}\")\n",
     "print(f\"Using DB: {db_output}\")\n",
@@ -277,7 +277,7 @@
     "        thresholds_offset_hard_mg,\n",
     "        thresholds_offset_hard_lg,\n",
     "    ]\n",
-    "print(f\"Will use the following hard offset thresholds\")\n",
+    "print(\"Will use the following hard offset thresholds\")\n",
     "for name, value in zip((\"High\", \"Medium\", \"Low\"), thresholds_offset_hard):\n",
     "    print(f\"- {name} gain: {value}\")\n",
     "\n",
@@ -312,7 +312,6 @@
     "print(f\"Will process a total of {total_files} files ({total_file_size:.02f} GB).\")\n",
     "\n",
     "inp = []\n",
-    "inp_modules = []\n",
     "for gain_index, (gain, qm_file_map) in enumerate(gain_mapped_files.items()):\n",
     "    for module_index in modules:\n",
     "        qm = module_index_to_qm(module_index)\n",
@@ -346,6 +345,7 @@
     "parallel_num_threads = multiprocessing.cpu_count() // parallel_num_procs\n",
     "print(f\"Will use {parallel_num_procs} processes with {parallel_num_threads} threads each\")\n",
     "\n",
+    "\n",
     "def characterize_module(\n",
     "    fast_data_filename: str, channel: int, gain_index: int\n",
     ") -> Tuple[np.array, np.array, np.array, np.array, int, np.array, int, float]:\n",
@@ -385,7 +385,7 @@
     "            first_index = int(first[status != 0][0])\n",
     "        im = np.array(infile[f\"{h5path_f}/data\"][first_index:last_index,...])\n",
     "        cell_ids = np.squeeze(infile[f\"{h5path_f}/cellId\"][first_index:last_index,...])\n",
-    "    \n",
+    "\n",
     "    if interlaced:\n",
     "        if not fixed_gain_mode:\n",
     "            ga = im[1::2, 0, ...]\n",
@@ -399,7 +399,7 @@
     "    im = np.transpose(im)\n",
     "    if not fixed_gain_mode:\n",
     "        ga = np.transpose(ga)\n",
-    "    \n",
+    "\n",
     "    context = psh.context.ThreadContext(num_workers=parallel_num_threads)\n",
     "    offset = context.alloc(shape=(im.shape[0], im.shape[1], num_cells), dtype=np.float64)\n",
     "    noise = context.alloc(like=offset)\n",
@@ -420,6 +420,7 @@
     "            ga_slice = ga[..., cell_slice_index]\n",
     "            gains[..., cell_number] = np.median(ga_slice, axis=2)\n",
     "            gains_std[..., cell_number] = np.std(ga_slice, axis=2)\n",
+    "\n",
     "    context.map(process_cell, np.unique(cell_ids))\n",
     "\n",
     "    # bad pixels\n",
@@ -430,8 +431,8 @@
     "\n",
     "    bp[(offset < offset_mn-thresholds_offset_sigma*offset_std) |\n",
     "       (offset > offset_mn+thresholds_offset_sigma*offset_std)] |= BadPixels.OFFSET_OUT_OF_THRESHOLD\n",
-    "    bp[(offset < local_thresholds_offset_hard[0]) | (\n",
-    "        offset > local_thresholds_offset_hard[1])] |= BadPixels.OFFSET_OUT_OF_THRESHOLD\n",
+    "    bp[(offset < local_thresholds_offset_hard[0]) |\n",
+    "       (offset > local_thresholds_offset_hard[1])] |= BadPixels.OFFSET_OUT_OF_THRESHOLD\n",
     "    bp[~np.isfinite(offset)] |= BadPixels.OFFSET_NOISE_EVAL_ERROR\n",
     "\n",
     "    # noise related bad pixels\n",
@@ -467,7 +468,7 @@
     "if not fixed_gain_mode:\n",
     "    gain_g = OrderedDict()\n",
     "    gainstd_g = OrderedDict()\n",
-    "    \n",
+    "\n",
     "all_cells = []\n",
     "all_acq_rate = []\n",
     "\n",
@@ -596,14 +597,14 @@
     "# Create mapping from module(s) (qm) to karabo_da(s) and PDU(s)\n",
     "qm_dict = OrderedDict()\n",
     "all_pdus = get_pdu_from_db(\n",
-    "        karabo_id,\n",
-    "        karabo_da,\n",
-    "        constant=iCalibrationDB.CalibrationConstant(),\n",
-    "        condition=condition,\n",
-    "        cal_db_interface=cal_db_interface,\n",
-    "        snapshot_at=creation_time.isoformat(),\n",
-    "        timeout=cal_db_timeout\n",
-    "    )\n",
+    "    karabo_id,\n",
+    "    karabo_da,\n",
+    "    constant=iCalibrationDB.CalibrationConstant(),\n",
+    "    condition=condition,\n",
+    "    cal_db_interface=cal_db_interface,\n",
+    "    snapshot_at=creation_time.isoformat(),\n",
+    "    timeout=cal_db_timeout\n",
+    ")\n",
     "for module_index, module_da, module_pdu in zip(modules, karabo_da, all_pdus):\n",
     "    qm = module_index_to_qm(module_index)\n",
     "    qm_dict[qm] = {\n",
@@ -654,9 +655,9 @@
    "source": [
     "# Start retrieving existing constants for comparison\n",
     "qm_x_const = [(qm, const) for const in res[qm] for qm in res]\n",
+    "\n",
+    "\n",
     "def retrieve_old_constant(qm, const):\n",
-    "    qm_db = qm_dict[qm]\n",
-    "    this_karabo_da = qm_db[\"karabo_da\"]\n",
     "    dconst = getattr(iCalibrationDB.Constants.AGIPD, const)()\n",
     "\n",
     "    # This should be used in case of running notebook\n",
@@ -665,8 +666,8 @@
     "    # TODO: Set db_module to \"\" by default in the first cell\n",
     "\n",
     "    data, mdata = get_from_db(\n",
-    "        karabo_id, \n",
-    "        this_karabo_da,\n",
+    "        karabo_id,\n",
+    "        qm_dict[qm][\"karabo_da\"],\n",
     "        constant=dconst,\n",
     "        condition=condition,\n",
     "        empty_constant=None,\n",
@@ -783,7 +784,7 @@
     "        BadPixels.OFFSET_OUT_OF_THRESHOLD | BadPixels.NOISE_OUT_OF_THRESHOLD |\n",
     "        BadPixels.GAIN_THRESHOLDING_ERROR: ('MIXED', '#BFDF009F')\n",
     "    }\n",
-    "    \n",
+    "\n",
     "    display(Markdown(\"\"\"\n",
     "\n",
     "    ## Global Bad Pixel Behaviour ##\n",
@@ -847,7 +848,6 @@
     "        bp_thresh[mod][...,:2] = con[...,:2]\n",
     "        bp_thresh[mod][...,2:] = con\n",
     "\n",
-    "\n",
     "    create_constant_overview(thresholds_g, \"Threshold (ADU)\", max_cells, 4000, 10000, 5,\n",
     "                             badpixels=[bp_thresh, np.nan],\n",
     "                             gmap=['HG-MG Threshold', 'MG-LG Threshold', 'High gain', 'Medium gain', 'low gain'],\n",
@@ -916,7 +916,6 @@
     "bits = [BadPixels.NOISE_OUT_OF_THRESHOLD, BadPixels.OFFSET_OUT_OF_THRESHOLD, BadPixels.OFFSET_NOISE_EVAL_ERROR, BadPixels.GAIN_THRESHOLDING_ERROR]\n",
     "for qm in badpix_g.keys():\n",
     "    for gain in range(3):\n",
-    "\n",
     "        l_data = []\n",
     "        l_data_old = []\n",
     "\n",
@@ -952,8 +951,7 @@
     "        table.append(['', '', '', ''])\n",
     "\n",
     "display(Markdown('''\n",
-    "\n",
-    "### Number of bad pixels ###\n",
+    "### Number of bad pixels\n",
     "\n",
     "One pixel can be bad for different reasons, therefore, the sum of all types of bad pixels can be more than the number of all bad pixels.\n",
     "\n",
@@ -983,6 +981,7 @@
     "\n",
     "constants_x_qms = list(itertools.product(constants, res.keys()))\n",
     "\n",
+    "\n",
     "def compute_table(const, qm):\n",
     "    if const == 'ThresholdsDark':\n",
     "        table = [['','HG-MG threshold', 'HG-MG threshold', 'MG-LG threshold', 'MG-LG threshold']]\n",
@@ -1031,7 +1030,7 @@
     "        rows = pool.map(compute_row, range(len(f_list)))\n",
     "\n",
     "    table.extend(rows)\n",
-    "            \n",
+    "\n",
     "    return table\n",
     "\n",
     "\n",