diff --git a/notebooks/LPD/LPD_Correct_Fast.ipynb b/notebooks/LPD/LPD_Correct_Fast.ipynb
index f624f5fae463ce84e008dd27fe3a92def823e8a6..12aab1e7d388a5ff70ef8a29ea129be41abfcc75 100644
--- a/notebooks/LPD/LPD_Correct_Fast.ipynb
+++ b/notebooks/LPD/LPD_Correct_Fast.ipynb
@@ -314,12 +314,12 @@
     "ccv_shape = (mem_cells, 256, 256, 3)\n",
     "\n",
     "constant_order = {\n",
-    "    'Offset':        (1, 0, 2, 3),\n",
-    "    'BadPixelsDark': (1, 0, 2, 3),\n",
-    "    'RelativeGain':  (1, 0, 2, 3),\n",
-    "    'FFMap':         (0, 1, 2, 3),\n",
-    "    'BadPixelsFF':   (0, 1, 2, 3),\n",
-    "    'GainAmpMap':    (0, 1, 2, 3),\n",
+    "    'Offset':        (2, 1, 0, 3),\n",
+    "    'BadPixelsDark': (2, 1, 0, 3),\n",
+    "    'RelativeGain':  (2, 1, 0, 3),\n",
+    "    'FFMap':         (2, 0, 1, 3),\n",
+    "    'BadPixelsFF':   (2, 0, 1, 3),\n",
+    "    'GainAmpMap':    (2, 0, 1, 3),\n",
     "}\n",
     "\n",
     "def prepare_constants(wid, index, aggregator):\n",
diff --git a/src/cal_tools/lpdalgs.pyx b/src/cal_tools/lpdalgs.pyx
index d7995b51b2a88335221892a044fba5e6bae88201..66b8b097c71a4a7cb6b1681e4678e0f04c2f43e7 100644
--- a/src/cal_tools/lpdalgs.pyx
+++ b/src/cal_tools/lpdalgs.pyx
@@ -19,16 +19,16 @@ cdef mask_t WRONG_GAIN_VALUE = BadPixels.WRONG_GAIN_VALUE, \
 @wraparound(False)
 @cdivision(True)
 def correct_lpd_frames(
-    # (pulse, x, y)
+    # (frame, x, y)
     raw_t[:, :, ::contiguous] in_raw,
     cell_t[::contiguous] in_cell,
 
-    # (pulse, x, y)
+    # (frame, x, y)
     data_t[:, :, ::contiguous] out_data,
     gain_t[:, :, ::contiguous] out_gain,
     mask_t[:, :, ::contiguous] out_mask,
 
-    # (x, y, cell, gain)
+    # (cell, x, y, gain)
     float[:, :, :, ::contiguous] ccv_offset,
     float[:, :, :, ::contiguous] ccv_gain,
     mask_t[:, :, :, ::contiguous] ccv_mask,
@@ -51,19 +51,14 @@ def correct_lpd_frames(
                 gain = <gain_t>((in_raw[frame, ss, fs] & 0x3000) >> 12)
 
                 if gain <= 2:
-                    mask = ccv_mask[ss, fs, cell, gain]
+                    mask = ccv_mask[cell, ss, fs, gain]
                 else:
                     data = 0.0
                     gain = 0
                     mask = WRONG_GAIN_VALUE
 
-                data = data - ccv_offset[ss, fs, cell, gain]
-
-                if ccv_gain[ss, fs, cell, gain] != 0.0:
-                    data = data * ccv_gain[ss, fs, cell, gain]
-                else:
-                    data = 0.0
-                    mask = mask | VALUE_IS_NAN
+                data = data - ccv_offset[cell, ss, fs, gain]
+                data = data * ccv_gain[cell, ss, fs, gain]
 
                 if data > 1e7 or data < -1e7:
                     data = 0.0