diff --git a/CHANGELOG.md b/CHANGELOG.md
index fccee5afaddb5526ac67ba60f6243a41dde32fc5..b27a76d384da92637687a206d7ce9bfa766155fb 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,6 +1,9 @@
 # CHANGELOG
 All changes to the Metis L1 pipeline are documented in this file.
 
+## 2.3.1 - 2021-04-19
+- Fixed a bug that caused an incorrect FITS file format: images with unsigned or long integer data type were saved as signed integers with the wrong BSCALE and BZERO scale keywords.
+
 ## 2.3 - 2021-03-10
 - Fix a bug that caused incorrect pixel counts in re-binned images. Pixel counts are now correctly multiplied by the square of the binning factor after re-binning.
 - Introduce the correction for the total effective exposure time: pixel counts are now multiplied by the number of frames that were averaged during the acquisition, so as not to change the real signal-to-noise statistics in each pixel, related to counts integrated over the total effective exposure time. The XPOSURE and NSUMEXP keywords of the FITS, which are affected, are properly updated using parameters DIT, NDIT, NDIT1, and NDIT2.
@@ -8,7 +11,7 @@ All changes to the Metis L1 pipeline are documented in this file.
 - Fix a bug that caused some keywords in the FITS header of light curves to be incorrectly ordered.
 
 ## 2.2.1 – 2021-02-23
-- Minor changes and optimisations
+- Minor changes and optimisations.
 
 ## 2.2 – 2020-11-25
 - Change the way how the house-keeping parameters are saved into the FITS binary table, in order to prevent very long computation times when the house-keeping parameter table is large in data volume.
diff --git a/metis_l1_prep.pro b/metis_l1_prep.pro
index ed93f2f57edd5b2e53592503ddc3da4ba526c4aa..534afba1990360db36b3d3560ef0ad19ed838b8a 100644
--- a/metis_l1_prep.pro
+++ b/metis_l1_prep.pro
@@ -202,21 +202,21 @@ pro metis_l1_prep
 	telapse = float(obt_end - obt_beg)
 
 	dit = fxpar(metadata_extension_header, 'DIT')
-	ndit = fxpar(metadata_extension_header, 'NDIT', missing = 1.)
-	ndit1 = fxpar(metadata_extension_header, 'NDIT1', missing = 1.)
-	ndit2 = fxpar(metadata_extension_header, 'NDIT2', missing = 1.)
+	ndit = fxpar(metadata_extension_header, 'NDIT', missing = 1L)
+	ndit1 = fxpar(metadata_extension_header, 'NDIT1', missing = 1L)
+	ndit2 = fxpar(metadata_extension_header, 'NDIT2', missing = 1L)
 
 	if datatype le 6 then begin
-		xposure = dit/1000. * ndit * ndit1 * ndit2
-		nsumexp = fix(ndit * ndit1 * ndit2)
+		nsumexp = ndit * ndit1 * ndit2
+		xposure = dit/1000. * nsumexp
 		data = data * nsumexp
 
-		if max(data, /nan) gt 32768 then data = long(data) else data = fix(data)
+		if max(data, /nan) lt 32768 then data = fix(data)
 
 		datamin = min(data, /nan)
-		datamax = max(data, /nan)
-
 		fxaddpar, primary_header, 'DATAMIN', datamin
+
+		datamax = max(data, /nan)
 		fxaddpar, primary_header, 'DATAMAX', datamax
 
 		if ~ isa(comment) then comment = !null