diff --git a/p348reco/p348reco.h b/p348reco/p348reco.h
index f9d8f11aef98676c4a40c513549f195249b682c5..05f75325dae11fdcb57564e43e9f9fd19e5b484e 100644
--- a/p348reco/p348reco.h
+++ b/p348reco/p348reco.h
@@ -252,17 +252,17 @@ struct Cell {
     //In case the fit is enabled, check the fitted peak that has the best timing.
     //If the fit result does not exists, reset the energy and time to 0
     if (calib->doWaveformFit){
+      amplitude = 0;
+      energy = 0;
+      t0 = 0;
+      amplitude_sample = 0;
       const na64util::iMSADCReco::PeakInfo * pi = peak_Best_fitted(method,master);
       if (pi) {
-        amplitude = pi->rawAmp;
-        energy = amplitude * calib->K;
-        t0 = pi->time/calib->adc.sampling_interval; //the cell t0 has to be in unit of samples
-        amplitude_sample = pi->sampleNo;
-      }else{
-        amplitude = 0;
-        energy = 0;
-        t0 = 0;
-      }
+          amplitude = pi->rawAmp;
+          energy = amplitude * calib->K;
+          t0 = pi->time/calib->adc.sampling_interval; //the cell t0 has to be in unit of samples
+          amplitude_sample = pi->sampleNo;
+       }
     }
   }
   
@@ -361,6 +361,7 @@ struct Cell {
     const na64util::iMSADCReco::PeakInfo * bestFittedPeak = nullptr;
     for(const auto & fittedPeak : fittedPeaksInfo) {
         if(!fittedPeak.are_amp_and_time_valid()) continue;
+        if (!fittedPeak.fitFunctionUserdata) continue;
         double A = fittedPeak.rawAmp;
         if (A<A_max) continue;
         A_max = A;
@@ -386,6 +387,7 @@ struct Cell {
     const na64util::iMSADCReco::PeakInfo * bestFittedPeak = nullptr;
     for(const auto & fittedPeak : fittedPeaksInfo) {
         if(!fittedPeak.are_amp_and_time_valid()) continue;
+        if (!fittedPeak.fitFunctionUserdata) continue;
         double tDelta = fabs(texpected - fittedPeak.time);
         if(tDelta > tMin) continue;
         tMin = tDelta;