diff --git a/lalsimulation/lib/LALSimIMR.h b/lalsimulation/lib/LALSimIMR.h
index b4b3421b536b20e0e377b6ce47e7f7ede77b35b9..b08cc8d8e06d1bf61d89753b0c07320ff4cffff9 100644
--- a/lalsimulation/lib/LALSimIMR.h
+++ b/lalsimulation/lib/LALSimIMR.h
@@ -682,6 +682,37 @@ int XLALSimIMRPhenomXHMAmplitude(
       LALDict *lalParams                   /**< Extra params */
   );
 
+
+int XLALSimIMRPhenomXHM_SpheroidalPhase(
+  REAL8Sequence **phase, /**< [out] FD waveform */
+  const REAL8Sequence *freqs_In,                /**< frequency array to evaluate model (positives) */
+  UINT4 ell,                           /**< l index of the mode */
+  INT4 emm,                            /**< m index of the mode */
+  REAL8 m1_SI,                         /**< Mass of companion 1 (kg) */
+  REAL8 m2_SI,                         /**< Mass of companion 2 (kg) */
+  REAL8 chi1L,                         /**< Dimensionless aligned spin of companion 1 */
+  REAL8 chi2L,                         /**< Dimensionless aligned spin of companion 2 */
+  REAL8 distance,                      /**< Luminosity distance (m) */
+  REAL8 phiRef,                        /**< Orbital phase at fRef (rad) */
+  REAL8 fRef_In,                       /**< Reference frequency (Hz) */
+  LALDict *lalParams                   /**< UNDOCUMENTED */
+);
+
+int XLALSimIMRPhenomXHM_SpheroidalAmplitude(
+  REAL8Sequence **amp, /**< [out] FD waveform */
+  const REAL8Sequence *freqs_In,                /**< frequency array to evaluate model (positives) */
+  UINT4 ell,                           /**< l index of the mode */
+  INT4 emm,                            /**< m index of the mode */
+  REAL8 m1_SI,                         /**< Mass of companion 1 (kg) */
+  REAL8 m2_SI,                         /**< Mass of companion 2 (kg) */
+  REAL8 chi1L,                         /**< Dimensionless aligned spin of companion 1 */
+  REAL8 chi2L,                         /**< Dimensionless aligned spin of companion 2 */
+  REAL8 distance,                      /**< Luminosity distance (m) */
+  REAL8 phiRef,                        /**< Orbital phase at fRef (rad) */
+  REAL8 fRef_In,                       /**< Reference frequency (Hz) */
+  LALDict *lalParams                   /**< UNDOCUMENTED */
+);
+
 int XLALSimIMRPhenomXPHM(
   COMPLEX16FrequencySeries **hptilde,         /**< [out] Frequency-domain waveform h+ */
   COMPLEX16FrequencySeries **hctilde,         /**< [out] Frequency-domain waveform hx */
diff --git a/lalsimulation/lib/LALSimIMRPhenomXHM.c b/lalsimulation/lib/LALSimIMRPhenomXHM.c
index 6877cae3c121125a9fc51d4a7fcb7babb66d0610..71d063a6fbf2baaab2515b3e1070bcda3b062861 100644
--- a/lalsimulation/lib/LALSimIMRPhenomXHM.c
+++ b/lalsimulation/lib/LALSimIMRPhenomXHM.c
@@ -581,7 +581,7 @@ int IMRPhenomXHMGenerateFDOneMode(
 
     IMRPhenomX_UsefulPowers powers_of_Mf;
     REAL8 Msec = pWF->M_sec;    // Variable to transform Hz to Mf
-    REAL8 Amp0 = pWFHM->Amp0;   // Transform amplitude from NR to physical units
+    REAL8 Amp0 = pWF->amp0;   // Transform amplitude from NR to physical units
     REAL8 amp, phi;
 
     /* Multiply by (-1)^l to get the true h_l-m(f) */
@@ -621,8 +621,8 @@ int IMRPhenomXHMGenerateFDOneMode(
           }
           else
           {
-            amp = IMRPhenomXHM_Amplitude_ModeMixing(Mf, &powers_of_Mf, pAmp, pPhase, pWFHM, pAmp22, pPhase22, pWF);
-            phi = IMRPhenomXHM_Phase_ModeMixing(Mf, &powers_of_Mf, pAmp, pPhase, pWFHM, pAmp22, pPhase22, pWF);
+            amp = IMRPhenomXHM_Amplitude_ModeMixing(&powers_of_Mf, pAmp, pPhase, pWFHM, pAmp22, pPhase22, pWF);
+            phi = IMRPhenomXHM_Phase_ModeMixing(&powers_of_Mf, pAmp, pPhase, pWFHM, pAmp22, pPhase22, pWF);
             /* Reconstruct waveform: h_l-m(f) = A(f) * Exp[I phi(f)] */
             ((*htildelm)->data->data)[idx+offset] = Amp0 * amp * cexp(I * phi);
 
@@ -654,8 +654,8 @@ int IMRPhenomXHMGenerateFDOneMode(
           }
           else
           {
-            amp = IMRPhenomXHM_Amplitude_noModeMixing(Mf, &powers_of_Mf, pAmp, pWFHM);
-            phi = IMRPhenomXHM_Phase_noModeMixing(Mf, &powers_of_Mf, pPhase, pWFHM, pWF);
+            amp = IMRPhenomXHM_Amplitude_noModeMixing(&powers_of_Mf, pAmp, pWFHM);
+            phi = IMRPhenomXHM_Phase_noModeMixing(&powers_of_Mf, pPhase, pWFHM, pWF);
             /* Reconstruct waveform: h_l-m(f) = A(f) * Exp[I phi(f)] */
             ((*htildelm)->data->data)[idx+offset] = Amp0 * amp * cexp(I * phi);
             #if DEBUG == 1
@@ -1021,6 +1021,321 @@ int XLALSimIMRPhenomXHMModes(
 }
 
 
+int XLALSimIMRPhenomXHM_SpheroidalPhase(
+  REAL8Sequence **phase, /**< [out] FD waveform */
+  const REAL8Sequence *freqs,                /**< frequency array to evaluate model (positives) */
+  UINT4 ell,                           /**< l index of the mode */
+  INT4 emm,                            /**< m index of the mode */
+  REAL8 m1_SI,                         /**< Mass of companion 1 (kg) */
+  REAL8 m2_SI,                         /**< Mass of companion 2 (kg) */
+  REAL8 chi1L,                         /**< Dimensionless aligned spin of companion 1 */
+  REAL8 chi2L,                         /**< Dimensionless aligned spin of companion 2 */
+  REAL8 distance,                      /**< Luminosity distance (m) */
+  REAL8 phiRef,                        /**< Orbital phase at fRef (rad) */
+  REAL8 fRef_In,                       /**< Reference frequency (Hz) */
+  LALDict *lalParams                   /**< UNDOCUMENTED */
+)
+{
+
+    /* Variable to check correct calls to functions. */
+    INT4 status = 0;
+
+    /* Sanity checks */
+    if(*phase)       { XLAL_CHECK(NULL != phase, XLAL_EFAULT);                                   }
+    if(fRef_In  <  0.0) { XLAL_ERROR(XLAL_EDOM, "fRef_In must be positive or set to 0 to ignore.\n");  }
+    if(m1_SI    <= 0.0) { XLAL_ERROR(XLAL_EDOM, "m1 must be positive.\n");                             }
+    if(m2_SI    <= 0.0) { XLAL_ERROR(XLAL_EDOM, "m2 must be positive.\n");                             }
+    if(distance <  0.0) { XLAL_ERROR(XLAL_EDOM, "Distance must be positive and greater than 0.\n");    }
+
+    /*
+      Perform a basic sanity check on the region of the parameter space in which model is evaluated. Behaviour is as follows:
+        - For mass ratios <= 20.0 and spins <= 0.99: no warning messages.
+        - For 1000 > mass ratio > 20 and spins <= 0.99: print a warning message that we are extrapolating outside of *NR* calibration domain.
+        - For mass ratios > 1000: throw a hard error that model is not valid.
+        - For spins > 0.99: throw a warning that we are extrapolating the model to extremal
+
+    */
+    REAL8 mass_ratio;
+    if(m1_SI > m2_SI)
+    {
+      mass_ratio = m1_SI / m2_SI;
+    }
+    else
+    {
+      mass_ratio = m2_SI / m1_SI;
+    }
+    if(mass_ratio > 20.0  ) { XLAL_PRINT_INFO("Warning: Extrapolating outside of Numerical Relativity calibration domain."); }
+    if(mass_ratio > 1000. && fabs(mass_ratio - 1000) > 1e-12) { XLAL_ERROR(XLAL_EDOM, "ERROR: Model not valid at mass ratios beyond 1000."); } // The 1e-12 is to avoid rounding errors
+    if(fabs(chi1L) > 0.99 || fabs(chi2L) > 0.99) { XLAL_PRINT_INFO("Warning: Extrapolating to extremal spins, model is not trusted."); }
+
+    /* Use an auxiliar laldict to not overwrite the input argument */
+    LALDict *lalParams_aux;
+    /* setup mode array */
+    if (lalParams == NULL)
+    {
+        lalParams_aux = XLALCreateDict();
+    }
+    else{
+        lalParams_aux = XLALDictDuplicate(lalParams);
+    }
+    lalParams_aux = IMRPhenomXHM_setup_mode_array(lalParams_aux);
+    LALValue *ModeArray = XLALSimInspiralWaveformParamsLookupModeArray(lalParams_aux);
+
+    /* first check if (l,m) mode is 'activated' in the ModeArray */
+    /* if activated then generate the mode, else skip this mode. */
+    if (XLALSimInspiralModeArrayIsModeActive(ModeArray, ell, emm) != 1 )
+    { /* skip mode */
+      XLALPrintError("XLAL Error - %i%i mode is not included\n", ell, emm);
+      XLAL_ERROR(XLAL_EDOM);
+    } /* else: generate mode */
+
+    /* Get minimum and maximum frequencies. */
+    REAL8 f_min_In  = freqs->data[0];
+    REAL8 f_max_In  = freqs->data[freqs->length - 1];
+
+
+    /* Initialize the useful powers of LAL_PI */
+    status = IMRPhenomX_Initialize_Powers(&powers_of_lalpiHM, LAL_PI);
+    XLAL_CHECK(XLAL_SUCCESS == status, XLAL_EFUNC, "Failed to initialize useful powers of LAL_PI.");
+    status = IMRPhenomX_Initialize_Powers(&powers_of_lalpi, LAL_PI);
+    XLAL_CHECK(XLAL_SUCCESS == status, XLAL_EFUNC, "Failed to initialize useful powers of LAL_PI.");
+
+
+    /*
+      Initialize IMRPhenomX waveform struct and perform sanity check.
+      Passing deltaF = 0 tells us that freqs contains a frequency grid with non-uniform spacing.
+      The function waveform start at lowest given frequency.
+    */
+    IMRPhenomXWaveformStruct *pWF;
+    pWF = XLALMalloc(sizeof(IMRPhenomXWaveformStruct));
+    status = IMRPhenomXSetWaveformVariables(pWF,m1_SI, m2_SI, chi1L, chi2L, 0.0, fRef_In, phiRef, f_min_In, f_max_In, distance, 0.0, lalParams_aux, PHENOMXDEBUG);
+    XLAL_CHECK(XLAL_SUCCESS == status, XLAL_EFUNC, "Error:  failed.\n");
+
+
+    // allocate qnm struct
+    QNMFits *qnms = (QNMFits *) XLALMalloc(sizeof(QNMFits));
+    IMRPhenomXHM_Initialize_QNMs(qnms);
+
+    // Populate pWFHM
+    IMRPhenomXHMWaveformStruct *pWFHM = (IMRPhenomXHMWaveformStruct *) XLALMalloc(sizeof(IMRPhenomXHMWaveformStruct));
+    IMRPhenomXHM_SetHMWaveformVariables(ell, abs(emm), pWFHM, pWF, qnms, lalParams);
+    LALFree(qnms);
+
+    /* Allocate coefficients of 22 mode */
+    IMRPhenomXAmpCoefficients *pAmp22=(IMRPhenomXAmpCoefficients *) XLALMalloc(sizeof(IMRPhenomXAmpCoefficients));
+    IMRPhenomXPhaseCoefficients *pPhase22=(IMRPhenomXPhaseCoefficients *) XLALMalloc(sizeof(IMRPhenomXPhaseCoefficients));
+    IMRPhenomXGetPhaseCoefficients(pWF, pPhase22);
+
+    /* Allocate and initialize the PhenomXHM lm amplitude and phae coefficients struct */
+    IMRPhenomXHMAmpCoefficients *pAmp = (IMRPhenomXHMAmpCoefficients*) XLALMalloc(sizeof(IMRPhenomXHMAmpCoefficients));
+    IMRPhenomXHMPhaseCoefficients *pPhase = (IMRPhenomXHMPhaseCoefficients*) XLALMalloc(sizeof(IMRPhenomXHMPhaseCoefficients));
+
+    /* Allocate and initialize the PhenomXHM lm phase and amp coefficients struct */
+    IMRPhenomXHM_FillAmpFitsArray(pAmp);
+    IMRPhenomXHM_FillPhaseFitsArray(pPhase);
+
+    /* Get coefficients for Amplitude and phase */
+    if (pWFHM->MixingOn == 1) {
+        // For mode with mixing we need the spheroidal coeffs of the 32 phase and the 22 amplitude coeffs.
+        GetSpheroidalCoefficients(pPhase, pPhase22, pWFHM, pWF);
+        IMRPhenomXGetAmplitudeCoefficients(pWF, pAmp22);
+    }
+    IMRPhenomXHM_GetAmplitudeCoefficients(pAmp, pPhase, pAmp22, pPhase22, pWFHM, pWF);
+    IMRPhenomXHM_GetPhaseCoefficients(pAmp, pPhase, pAmp22, pPhase22, pWFHM, pWF,lalParams);
+
+    IMRPhenomX_UsefulPowers powers_of_Mf;
+    REAL8 Msec = pWF->M_sec;    // Variable to transform Hz to Mf
+
+    *phase = XLALCreateREAL8Sequence(freqs->length);
+
+    for (UINT4 idx = 0; idx < freqs->length; idx++)
+    {
+      REAL8 Mf    = Msec * freqs->data[idx];
+      INT4 initial_status     = IMRPhenomX_Initialize_Powers(&powers_of_Mf,Mf);
+      if(initial_status != XLAL_SUCCESS)
+      {
+        XLALPrintError("IMRPhenomX_Initialize_Powers failed for Mf, initial_status=%d",initial_status);
+      }
+      else
+      {
+        ((*phase)->data)[idx] = IMRPhenomXHM_RD_Phase_AnsatzInt(Mf, &powers_of_Mf, pWFHM, pPhase);
+      }
+    }
+
+
+    /* Free memory */
+    LALFree(pWF);
+    LALFree(pWFHM);
+    LALFree(pPhase);
+    LALFree(pPhase22);
+    LALFree(pAmp);
+    LALFree(pAmp22);
+    XLALDestroyValue(ModeArray);
+    XLALDestroyDict(lalParams_aux);
+
+
+    return XLAL_SUCCESS;
+}
+
+
+int XLALSimIMRPhenomXHM_SpheroidalAmplitude(
+  REAL8Sequence **amplitude, /**< [out] FD waveform */
+  const REAL8Sequence *freqs,                /**< frequency array to evaluate model (positives) */
+  UINT4 ell,                           /**< l index of the mode */
+  INT4 emm,                            /**< m index of the mode */
+  REAL8 m1_SI,                         /**< Mass of companion 1 (kg) */
+  REAL8 m2_SI,                         /**< Mass of companion 2 (kg) */
+  REAL8 chi1L,                         /**< Dimensionless aligned spin of companion 1 */
+  REAL8 chi2L,                         /**< Dimensionless aligned spin of companion 2 */
+  REAL8 distance,                      /**< Luminosity distance (m) */
+  REAL8 phiRef,                        /**< Orbital phase at fRef (rad) */
+  REAL8 fRef_In,                       /**< Reference frequency (Hz) */
+  LALDict *lalParams                   /**< UNDOCUMENTED */
+)
+{
+
+    /* Variable to check correct calls to functions. */
+    INT4 status = 0;
+
+    /* Sanity checks */
+    if(*amplitude)       { XLAL_CHECK(NULL != amplitude, XLAL_EFAULT);                                   }
+    if(fRef_In  <  0.0) { XLAL_ERROR(XLAL_EDOM, "fRef_In must be positive or set to 0 to ignore.\n");  }
+    if(m1_SI    <= 0.0) { XLAL_ERROR(XLAL_EDOM, "m1 must be positive.\n");                             }
+    if(m2_SI    <= 0.0) { XLAL_ERROR(XLAL_EDOM, "m2 must be positive.\n");                             }
+    if(distance <  0.0) { XLAL_ERROR(XLAL_EDOM, "Distance must be positive and greater than 0.\n");    }
+
+    /*
+      Perform a basic sanity check on the region of the parameter space in which model is evaluated. Behaviour is as follows:
+        - For mass ratios <= 20.0 and spins <= 0.99: no warning messages.
+        - For 1000 > mass ratio > 20 and spins <= 0.99: print a warning message that we are extrapolating outside of *NR* calibration domain.
+        - For mass ratios > 1000: throw a hard error that model is not valid.
+        - For spins > 0.99: throw a warning that we are extrapolating the model to extremal
+
+    */
+    REAL8 mass_ratio;
+    if(m1_SI > m2_SI)
+    {
+      mass_ratio = m1_SI / m2_SI;
+    }
+    else
+    {
+      mass_ratio = m2_SI / m1_SI;
+    }
+    if(mass_ratio > 20.0  ) { XLAL_PRINT_INFO("Warning: Extrapolating outside of Numerical Relativity calibration domain."); }
+    if(mass_ratio > 1000. && fabs(mass_ratio - 1000) > 1e-12) { XLAL_ERROR(XLAL_EDOM, "ERROR: Model not valid at mass ratios beyond 1000."); } // The 1e-12 is to avoid rounding errors
+    if(fabs(chi1L) > 0.99 || fabs(chi2L) > 0.99) { XLAL_PRINT_INFO("Warning: Extrapolating to extremal spins, model is not trusted."); }
+
+    /* Use an auxiliar laldict to not overwrite the input argument */
+    LALDict *lalParams_aux;
+    /* setup mode array */
+    if (lalParams == NULL)
+    {
+        lalParams_aux = XLALCreateDict();
+    }
+    else{
+        lalParams_aux = XLALDictDuplicate(lalParams);
+    }
+    lalParams_aux = IMRPhenomXHM_setup_mode_array(lalParams_aux);
+    LALValue *ModeArray = XLALSimInspiralWaveformParamsLookupModeArray(lalParams_aux);
+
+    /* first check if (l,m) mode is 'activated' in the ModeArray */
+    /* if activated then generate the mode, else skip this mode. */
+    if (XLALSimInspiralModeArrayIsModeActive(ModeArray, ell, emm) != 1 )
+    { /* skip mode */
+      XLALPrintError("XLAL Error - %i%i mode is not included\n", ell, emm);
+      XLAL_ERROR(XLAL_EDOM);
+    } /* else: generate mode */
+
+    /* Get minimum and maximum frequencies. */
+    REAL8 f_min_In  = freqs->data[0];
+    REAL8 f_max_In  = freqs->data[freqs->length - 1];
+
+
+    /* Initialize the useful powers of LAL_PI */
+    status = IMRPhenomX_Initialize_Powers(&powers_of_lalpiHM, LAL_PI);
+    XLAL_CHECK(XLAL_SUCCESS == status, XLAL_EFUNC, "Failed to initialize useful powers of LAL_PI.");
+    status = IMRPhenomX_Initialize_Powers(&powers_of_lalpi, LAL_PI);
+    XLAL_CHECK(XLAL_SUCCESS == status, XLAL_EFUNC, "Failed to initialize useful powers of LAL_PI.");
+
+
+    /*
+      Initialize IMRPhenomX waveform struct and perform sanity check.
+      Passing deltaF = 0 tells us that freqs contains a frequency grid with non-uniform spacing.
+      The function waveform start at lowest given frequency.
+    */
+    IMRPhenomXWaveformStruct *pWF;
+    pWF = XLALMalloc(sizeof(IMRPhenomXWaveformStruct));
+    status = IMRPhenomXSetWaveformVariables(pWF,m1_SI, m2_SI, chi1L, chi2L, 0.0, fRef_In, phiRef, f_min_In, f_max_In, distance, 0.0, lalParams_aux, PHENOMXDEBUG);
+    XLAL_CHECK(XLAL_SUCCESS == status, XLAL_EFUNC, "Error:  failed.\n");
+
+
+    // allocate qnm struct
+    QNMFits *qnms = (QNMFits *) XLALMalloc(sizeof(QNMFits));
+    IMRPhenomXHM_Initialize_QNMs(qnms);
+
+    // Populate pWFHM
+    IMRPhenomXHMWaveformStruct *pWFHM = (IMRPhenomXHMWaveformStruct *) XLALMalloc(sizeof(IMRPhenomXHMWaveformStruct));
+    IMRPhenomXHM_SetHMWaveformVariables(ell, abs(emm), pWFHM, pWF, qnms, lalParams);
+    LALFree(qnms);
+
+    /* Allocate coefficients of 22 mode */
+    IMRPhenomXAmpCoefficients *pAmp22=(IMRPhenomXAmpCoefficients *) XLALMalloc(sizeof(IMRPhenomXAmpCoefficients));
+    IMRPhenomXPhaseCoefficients *pPhase22=(IMRPhenomXPhaseCoefficients *) XLALMalloc(sizeof(IMRPhenomXPhaseCoefficients));
+    IMRPhenomXGetPhaseCoefficients(pWF, pPhase22);
+
+    /* Allocate and initialize the PhenomXHM lm amplitude and phae coefficients struct */
+    IMRPhenomXHMAmpCoefficients *pAmp = (IMRPhenomXHMAmpCoefficients*) XLALMalloc(sizeof(IMRPhenomXHMAmpCoefficients));
+    IMRPhenomXHMPhaseCoefficients *pPhase = (IMRPhenomXHMPhaseCoefficients*) XLALMalloc(sizeof(IMRPhenomXHMPhaseCoefficients));
+
+    /* Allocate and initialize the PhenomXHM lm phase and amp coefficients struct */
+    IMRPhenomXHM_FillAmpFitsArray(pAmp);
+    IMRPhenomXHM_FillPhaseFitsArray(pPhase);
+
+    /* Get coefficients for Amplitude and phase */
+    if (pWFHM->MixingOn == 1) {
+        // For mode with mixing we need the spheroidal coeffs of the 32 phase and the 22 amplitude coeffs.
+        GetSpheroidalCoefficients(pPhase, pPhase22, pWFHM, pWF);
+        IMRPhenomXGetAmplitudeCoefficients(pWF, pAmp22);
+    }
+    IMRPhenomXHM_GetAmplitudeCoefficients(pAmp, pPhase, pAmp22, pPhase22, pWFHM, pWF);
+    //FIXME: needed?
+    IMRPhenomXHM_GetPhaseCoefficients(pAmp, pPhase, pAmp22, pPhase22, pWFHM, pWF,lalParams);
+
+    IMRPhenomX_UsefulPowers powers_of_Mf;
+    REAL8 Msec = pWF->M_sec;    // Variable to transform Hz to Mf
+
+    *amplitude = XLALCreateREAL8Sequence(freqs->length);
+
+    for (UINT4 idx = 0; idx < freqs->length; idx++)
+    {
+      REAL8 Mf    = Msec * freqs->data[idx];
+      INT4 initial_status     = IMRPhenomX_Initialize_Powers(&powers_of_Mf,Mf);
+      if(initial_status != XLAL_SUCCESS)
+      {
+        XLALPrintError("IMRPhenomX_Initialize_Powers failed for Mf, initial_status=%d",initial_status);
+      }
+      else
+      {
+        ((*amplitude)->data)[idx] = IMRPhenomXHM_RD_Amp_Ansatz(&powers_of_Mf, pWFHM, pAmp) * pWFHM->Amp0;
+      }
+    }
+
+
+    /* Free memory */
+    LALFree(pWF);
+    LALFree(pWFHM);
+    LALFree(pPhase);
+    LALFree(pPhase22);
+    LALFree(pAmp);
+    LALFree(pAmp22);
+    XLALDestroyValue(ModeArray);
+    XLALDestroyDict(lalParams_aux);
+
+
+    return XLAL_SUCCESS;
+}
+
+
 /*********************************************/
 /*                                           */
 /*          MULTIMODE WAVEFORM               */
@@ -1351,6 +1666,10 @@ int XLALSimIMRPhenomXHM2(
      XLALSimInspiralWaveformParamsInsertPhenomXHMThresholdMband(lalParams_aux, 0);
    }
 
+   /* Initialize the useful powers of LAL_PI */
+      status = IMRPhenomX_Initialize_Powers(&powers_of_lalpi, LAL_PI);
+      XLAL_CHECK(XLAL_SUCCESS == status, status, "Failed to initialize useful powers of LAL_PI.");
+
    /* Initialize IMRPhenomX waveform struct and perform sanity check. */
    IMRPhenomXWaveformStruct *pWF;
    pWF = XLALMalloc(sizeof(IMRPhenomXWaveformStruct));
@@ -1647,9 +1966,10 @@ static int IMRPhenomXHM_MultiMode2(
 
   /* Allocate hptilde and hctilde */
   /* Coalescence time is fixed to t=0, shift by overall length in time. */
-  //XLAL_CHECK(XLALGPSAdd(&ligotimegps_zero, -1. / pWF->deltaF), XLAL_EFUNC, "Failed to shift the coalescence time to t=0. Tried to apply a shift of -1/df with df = %g.", pWF->deltaF);
   size_t n = (htildelm)->data->length;
-  XLAL_CHECK(XLALGPSAdd(&ligotimegps_zero, -1. / pWF->deltaF), XLAL_EFUNC, "Failed to shift the coalescence time to t=0. Tried to apply a shift of -1/df with df = %g.", pWF->deltaF);
+  if (pWF->deltaF > 0){
+    XLAL_CHECK(XLALGPSAdd(&ligotimegps_zero, -1. / pWF->deltaF), XLAL_EFUNC, "Failed to shift the coalescence time to t=0. Tried to apply a shift of -1/df with df = %g.", pWF->deltaF);
+  }
   *hptilde = XLALCreateCOMPLEX16FrequencySeries("hptilde: FD waveform", &(ligotimegps_zero), 0.0, pWF->deltaF, &lalStrainUnit, n);
   if (!(hptilde)){   XLAL_ERROR(XLAL_EFUNC);}
   memset((*hptilde)->data->data, 0, n * sizeof(COMPLEX16));  // what is this for??
@@ -1749,7 +2069,7 @@ static int IMRPhenomXHM_MultiMode2(
     else{
       minus1l = 1;
     }
-    Amp0 = minus1l * pWF->ampNorm * pWF->amp0;
+    Amp0 = minus1l * pWF->amp0; //Transform NR units to Physical units
 
     for (INT4 emm = 1; emm < (INT4)ell + 1; emm++){
       /* Loop over only positive m is intentional. The single mode function returns the negative mode h_l-m, and the positive is added automatically in IMRPhenomXHMFDAddMode. */
@@ -1815,8 +2135,8 @@ static int IMRPhenomXHM_MultiMode2(
             for (UINT4 idx = 0; idx < len; idx++)
             {
               COMPLEX16 wf22 = htilde22->data->data[idx + offset]; //This will be rescaled inside SpheroidalToSphericalRecycle for the rotation
-              amp = IMRPhenomXHM_Amplitude_ModeMixingRecycle(Mf[idx], &powers_of_Mf[idx], wf22, pAmp, pPhase, pWFHM);
-              phi = IMRPhenomXHM_Phase_ModeMixingRecycle(Mf[idx], &powers_of_Mf[idx], wf22, pAmp, pPhase, pWFHM);
+              amp = IMRPhenomXHM_Amplitude_ModeMixingRecycle(&powers_of_Mf[idx], wf22, pAmp, pPhase, pWFHM);
+              phi = IMRPhenomXHM_Phase_ModeMixingRecycle(&powers_of_Mf[idx], wf22, pAmp, pPhase, pWFHM);
               /* Reconstruct waveform: h(f) = A(f) * Exp[I phi(f)] */
               ((htildelm)->data->data)[idx+offset] = Amp0 * amp * cexp(I * phi);
             }
@@ -1825,8 +2145,8 @@ static int IMRPhenomXHM_MultiMode2(
           else{
             for (UINT4 idx = 0; idx < len; idx++)
             {
-              amp = IMRPhenomXHM_Amplitude_ModeMixing(Mf[idx], &powers_of_Mf[idx], pAmp, pPhase, pWFHM, pAmp22, pPhase22, pWF);
-              phi = IMRPhenomXHM_Phase_ModeMixing(Mf[idx], &powers_of_Mf[idx], pAmp, pPhase, pWFHM, pAmp22, pPhase22, pWF);
+              amp = IMRPhenomXHM_Amplitude_ModeMixing(&powers_of_Mf[idx], pAmp, pPhase, pWFHM, pAmp22, pPhase22, pWF);
+              phi = IMRPhenomXHM_Phase_ModeMixing(&powers_of_Mf[idx], pAmp, pPhase, pWFHM, pAmp22, pPhase22, pWF);
               /* Reconstruct waveform: h(f) = A(f) * Exp[I phi(f)] */
               ((htildelm)->data->data)[idx+offset] = Amp0 * amp * cexp(I * phi);
             }
@@ -1835,8 +2155,8 @@ static int IMRPhenomXHM_MultiMode2(
         else{
           for (UINT4 idx = 0; idx < len; idx++)
           {
-            amp = IMRPhenomXHM_Amplitude_noModeMixing(Mf[idx], &powers_of_Mf[idx], pAmp, pWFHM);
-            phi = IMRPhenomXHM_Phase_noModeMixing(Mf[idx], &powers_of_Mf[idx], pPhase, pWFHM, pWF);
+            amp = IMRPhenomXHM_Amplitude_noModeMixing(&powers_of_Mf[idx], pAmp, pWFHM);
+            phi = IMRPhenomXHM_Phase_noModeMixing(&powers_of_Mf[idx], pPhase, pWFHM, pWF);
             /* Reconstruct waveform: h(f) = A(f) * Exp[I phi(f)] */
             ((htildelm)->data->data)[idx+offset] = Amp0 * amp * cexp(I * phi);
           }
@@ -2015,6 +2335,17 @@ static int IMRPhenomXHMFDAddMode(
 * under https://git.ligo.org/waveforms/reviews/imrphenomx/wikis/home.
 * DCC link to the paper and supplementary material: https://dcc.ligo.org/P2000011-v2
 *
+* Waveform flags:
+* 
+*   PhenomXHMReleaseVersion: this flag was introduced after the recalibration of the higher modes amplitudes in 122022.
+*   The default value is 122022, pointing to the new release. The old release can be recovered setting this option to 122019.
+*   For future releases this flag will be updated.
+*
+*   NOTE: The following flags are only intended for further model development and not of general interest to the user. Changes from the implemented default values (https://git.ligo.org/waveforms/reviews/imrphenomxhm-amplitude-recalibration/-/wikis/home) are generally not advised. 
+*      IMRPhenomXHMInspiral(Intermediate)(Ringdown)Amp(Phase)FreqsVersion: controls the cutting frequencies between regions and the collocation points frequencies
+*      IMRPhenomXHMInspiral(Intermediate)(Ringdown)Amp(Phase)FitsVersion: controls the version of the parameter space fits for collocation points values and coefficients
+*      IMRPhenomXHMInspiral(Intermediate)(Ringdown)Amp(Phase)Version: controls the version of the ansatz. In the 122022 release the new format allows for more flexibility to choose the collocation points to be used
+*      The 122022 release does not modify the phases, so all the Phase flags point to the old value of PhaseVersion. Notice that the PhaseFreqs(Fits)Version flags cannot be modified through LALDict options.
 **/
 
 /** Returns amplitude of one single mode in a custom frequency array.
@@ -2141,7 +2472,7 @@ int XLALSimIMRPhenomXHMAmplitude(
     IMRPhenomXHMAmpCoefficients *pAmp = (IMRPhenomXHMAmpCoefficients*) XLALMalloc(sizeof(IMRPhenomXHMAmpCoefficients));
     IMRPhenomXHMPhaseCoefficients *pPhase = (IMRPhenomXHMPhaseCoefficients*) XLALMalloc(sizeof(IMRPhenomXHMPhaseCoefficients));
     
-    REAL8 Amp0, amp, Mf;
+    REAL8 Amp0 = 0, amp = 0, Mf;
     IMRPhenomX_UsefulPowers powers_of_Mf;
     
     if(ell ==2 && abs(emm) == 2){
@@ -2156,19 +2487,21 @@ int XLALSimIMRPhenomXHMAmplitude(
         IMRPhenomXHM_SetHMWaveformVariables(ell, abs(emm), pWFHM, pWF, qnms, lalParams_aux);
         LALFree(qnms);
         
-        Amp0 = pWFHM->Amp0;
-        
-        /* Allocate and initialize the PhenomXHM lm phase and amp coefficients struct */
-        IMRPhenomXHM_FillAmpFitsArray(pAmp);
-        
-        /* Get coefficients for Amplitude and phase */
-        if (pWFHM->MixingOn == 1)  {
-            IMRPhenomXHM_FillPhaseFitsArray(pPhase);
-            IMRPhenomXGetPhaseCoefficients(pWF, pPhase22);
-            GetSpheroidalCoefficients(pPhase, pPhase22, pWFHM, pWF);
-            IMRPhenomXGetAmplitudeCoefficients(pWF, pAmp22);
+        if(pWFHM->Ampzero==0){
+            Amp0 = pWFHM->Amp0;
+            
+            /* Allocate and initialize the PhenomXHM lm phase and amp coefficients struct */
+            IMRPhenomXHM_FillAmpFitsArray(pAmp);
+            
+            /* Get coefficients for Amplitude and phase */
+            if (pWFHM->MixingOn == 1)  {
+                IMRPhenomXHM_FillPhaseFitsArray(pPhase);
+                IMRPhenomXGetPhaseCoefficients(pWF, pPhase22);
+                GetSpheroidalCoefficients(pPhase, pPhase22, pWFHM, pWF);
+                IMRPhenomXGetAmplitudeCoefficients(pWF, pAmp22);
+            }
+            IMRPhenomXHM_GetAmplitudeCoefficients(pAmp, pPhase, pAmp22, pPhase22, pWFHM, pWF);
         }
-        IMRPhenomXHM_GetAmplitudeCoefficients(pAmp, pPhase, pAmp22, pPhase22, pWFHM, pWF);
     }
         
     *amplitude = XLALCreateREAL8Sequence(freqs->length);     
@@ -2188,12 +2521,12 @@ int XLALSimIMRPhenomXHMAmplitude(
             if(ell == 2 && abs(emm) == 2){
                 amp = IMRPhenomX_Amplitude_22(Mf, &powers_of_Mf, pAmp22, pWF);
             }
-            else{
+            else if (pWFHM->Ampzero==0){
                 if(pWFHM->MixingOn==1){
-                    amp = IMRPhenomXHM_Amplitude_ModeMixing(Mf, &powers_of_Mf, pAmp, pPhase, pWFHM, pAmp22, pPhase22, pWF);
+                    amp = IMRPhenomXHM_Amplitude_ModeMixing(&powers_of_Mf, pAmp, pPhase, pWFHM, pAmp22, pPhase22, pWF);
                 }
                 else{
-                    amp = IMRPhenomXHM_Amplitude_noModeMixing(Mf, &powers_of_Mf, pAmp, pWFHM);
+                    amp = IMRPhenomXHM_Amplitude_noModeMixing(&powers_of_Mf, pAmp, pWFHM);
                 }
             }            
             ((*amplitude)->data)[idx] = Amp0 * amp;
@@ -2332,12 +2665,12 @@ int XLALSimIMRPhenomXHMPhase(
     IMRPhenomXAmpCoefficients *pAmp22=(IMRPhenomXAmpCoefficients *) XLALMalloc(sizeof(IMRPhenomXAmpCoefficients));
     IMRPhenomXPhaseCoefficients *pPhase22=(IMRPhenomXPhaseCoefficients *) XLALMalloc(sizeof(IMRPhenomXPhaseCoefficients));
     IMRPhenomXGetPhaseCoefficients(pWF, pPhase22);
-    
+
     /* Allocate and initialize the PhenomXHM lm amplitude coefficients struct */
     IMRPhenomXHMAmpCoefficients *pAmp = (IMRPhenomXHMAmpCoefficients*) XLALMalloc(sizeof(IMRPhenomXHMAmpCoefficients));
     IMRPhenomXHMPhaseCoefficients *pPhase = (IMRPhenomXHMPhaseCoefficients*) XLALMalloc(sizeof(IMRPhenomXHMPhaseCoefficients));
     
-    REAL8 lina = 0, linb = 0;
+    REAL8 lina = 0, linb = 0, inveta=1./pWF->eta;
     if (ell == 2 && abs(emm) == 2){
         /* Initialize a struct containing useful powers of Mf at fRef */
         IMRPhenomX_UsefulPowers powers_of_MfRef;
@@ -2350,7 +2683,7 @@ int XLALSimIMRPhenomXHMPhase(
         IMRPhenomX_Phase_22_ConnectionCoefficients(pWF,pPhase22);
         linb = IMRPhenomX_TimeShift_22(pPhase22, pWF);
         /* Calculate phase at reference frequency: phifRef = 2.0*phi0 + LAL_PI_4 + PhenomXPhase(fRef) */
-        pWF->phifRef = -(1/pWF->eta * IMRPhenomX_Phase_22(pWF->MfRef, &powers_of_MfRef, pPhase22, pWF) + linb*pWF->MfRef + lina) + 2.0*pWF->phi0 + LAL_PI_4;
+        pWF->phifRef = -(inveta*IMRPhenomX_Phase_22(pWF->MfRef, &powers_of_MfRef, pPhase22, pWF) + linb*pWF->MfRef + lina) + 2.0*pWF->phi0 + LAL_PI_4;
     }
     else{ 
         // allocate qnm struct
@@ -2397,16 +2730,15 @@ int XLALSimIMRPhenomXHMPhase(
         else
         {
             if (ell ==2 && abs(emm) == 2){
-                phi = IMRPhenomX_Phase_22(Mf, &powers_of_Mf, pPhase22, pWF);
-                phi /= pWF->eta;
+                phi = inveta*IMRPhenomX_Phase_22(Mf, &powers_of_Mf, pPhase22, pWF);
                 phi += linb*Mf + lina + pWF->phifRef;
             }
             else{
                 if(pWFHM->MixingOn==1){
-                    phi = IMRPhenomXHM_Phase_ModeMixing(Mf, &powers_of_Mf, pAmp, pPhase, pWFHM, pAmp22, pPhase22, pWF);
+                    phi = IMRPhenomXHM_Phase_ModeMixing(&powers_of_Mf, pAmp, pPhase, pWFHM, pAmp22, pPhase22, pWF);
                 }
                 else{
-                    phi = IMRPhenomXHM_Phase_noModeMixing(Mf, &powers_of_Mf, pPhase, pWFHM, pWF);
+                    phi = IMRPhenomXHM_Phase_noModeMixing(&powers_of_Mf, pPhase, pWFHM, pWF);
                 }
             }            
             ((*phase)->data)[idx] = phi + addpi;
diff --git a/lalsimulation/lib/LALSimIMRPhenomXHM_inspiral.c b/lalsimulation/lib/LALSimIMRPhenomXHM_inspiral.c
index 55c26a23d96fe7f54df6f004aba7e7f9c0952627..d966f2fdb3fd9ca96319a1d2248324b59b14d999 100644
--- a/lalsimulation/lib/LALSimIMRPhenomXHM_inspiral.c
+++ b/lalsimulation/lib/LALSimIMRPhenomXHM_inspiral.c
@@ -43,271 +43,501 @@
 // Spin parameter S = chi_PN = chi_eff - 38/113 * eta * (chi1 + chi2)
 // chi_eff = (m1*chi1 + m2*chi2)/(m1 + m2)
 
+/* Start of Amp Parameter Space Fits */
 
-
-static double IMRPhenomXHM_Insp_Amp_21_iv1(double eta, double S, double chi1, double chi2, int InspAmpFlag) {
-    UNUSED double total=0, eta2,eta3,eta4,eta5,S2,S3;
+static double IMRPhenomXHM_Insp_Amp_21_iv1(IMRPhenomXWaveformStruct *pWF, int InspAmpFlag) {
+    double total=0;
     switch (InspAmpFlag){
         case 122018:{
+            double eta = pWF->eta;
+            double S = pWF->chiPNHat;
+            double eta2,eta3,eta4,eta5,S2;
             eta2 = pow(eta,2);
             eta3 = pow(eta,3);
             eta4 = pow(eta,4);
             eta5 = pow(eta,5);
             S2 = pow(S,2);
-            S3 = pow(S,3);
-            double noSpin = sqrt(1. - 4.*eta)*(0.037868557189995156 + 0.10740090317702103*eta + 1.963812986867654*eta2 - 16.706455229589558*eta3 + 69.75910808095745*eta4 - 98.3062466823662*eta5);
-            double eqSpin = sqrt(1. - 4.*eta)*S*(-0.007963757232702219 + 0.10627108779259965*eta - 0.008044970210401218*S + eta2*(-0.4735861262934258 - 0.5985436493302649*S - 0.08217216660522082*S2));
-            double uneqSpin = -0.257787704938017*(chi1 - 1.*chi2)*eta2*(1. + 8.75928187268504*eta2) - 0.2597503605427412*(chi1 - 1.*chi2)*eta2*S;
+            double noSpin = sqrt(1.-4.*eta)*(0.037868557189995156 + 0.10740090317702103*eta + 1.963812986867654*eta2 - 16.706455229589558*eta3 + 69.75910808095745*eta4 - 98.3062466823662*eta5);
+            double eqSpin = sqrt(1.-4.*eta)*S*(-0.007963757232702219 + 0.10627108779259965*eta - 0.008044970210401218*S + eta2*(-0.4735861262934258 - 0.5985436493302649*S - 0.08217216660522082*S2));
+            double uneqSpin = -0.257787704938017*pWF->dchi*eta2*(1. + 8.75928187268504*eta2) - 0.2597503605427412*pWF->dchi*eta2*S;
             total = noSpin + eqSpin + uneqSpin;
             break;
         }
-        default:{XLAL_ERROR_REAL8(XLAL_EINVAL,"Error in IMRPhenomXHM_Insp_Amp_21_iv1: version is not valid. Recommended version is 122018.");}
+        case 122022:{
+            double eta = pWF->eta;
+            double delta = pWF->delta;
+            double sqroot = sqrt(eta);
+            double S = pWF->chiPNHat;
+            double chidiff = pWF->dchi_half;
+            double eta1 = eta;
+            double eta2 = eta1 * eta1;
+            double eta3 = eta1 * eta2;
+            double eta4 = eta1 * eta3;
+            double eta5 = eta1 * eta4;
+            double S1 = S;
+            double S2 = S1 * S1;
+            double chidiff1 = chidiff;
+            total = fabs(chidiff1*eta5*(-3962.5020052272976 + 987.635855365408*S1 - 134.98527058315528*S2) + delta*(19.30531354642419 + 16.6640319856064*eta1 - 120.58166037019478*eta2 + 220.77233521626252*eta3)*sqroot + chidiff1*delta*(31.364509907424765*eta1 - 843.6414532232126*eta2 + 2638.3077554662905*eta3)*sqroot + chidiff1*delta*(32.374226994179054*eta1 - 202.86279451816662*eta2 + 347.1621871204769*eta3)*S1*sqroot + delta*S1*(-16.75726972301224*(1.1787350890261943 - 7.812073811917883*eta1 + 99.47071002831267*eta2 - 500.4821414428368*eta3 + 876.4704270866478*eta4) + 2.3439955698372663*(0.9373952326655807 + 7.176140122833879*eta1 - 279.6409723479635*eta2 + 2178.375177755584*eta3 - 4768.212511142035*eta4)*S1)*sqroot);
+            break;
+        }
+        default:{XLAL_ERROR_REAL8(XLAL_EINVAL,"Error in IMRPhenomXHM_Insp_Amp_21_iv1: version %i is not valid.", InspAmpFlag);}
     }
     return total;
 }
 
-static double IMRPhenomXHM_Insp_Amp_21_iv2(double eta, double S, double chi1, double chi2, int InspAmpFlag) {
-    UNUSED double total=0, delta=sqrt(1. - 4.*eta),eta2,eta3,eta4,S2,S3;
+static double IMRPhenomXHM_Insp_Amp_21_iv2(IMRPhenomXWaveformStruct *pWF, int InspAmpFlag) {
+    double total=0;
     switch (InspAmpFlag){
         case 122018:{
+            double eta = pWF->eta;
+            double S = pWF->chiPNHat;
+            double delta=sqrt(1.-4.*eta),eta2,eta3,eta4,S2;
             eta2 = pow(eta,2);
             eta3 = pow(eta,3);
             eta4 = pow(eta,4);
             S2 = pow(S,2);
-            S3 = pow(S,3);
-            double noSpin = sqrt(1. - 4.*eta)*(0.05511628628738656 - 0.12579599745414977*eta + 2.831411618302815*eta2 - 14.27268643447161*eta3 + 28.3307320191161*eta4);
-            double eqSpin = sqrt(1. - 4.*eta)*S*(-0.008692738851491525 + eta*(0.09512553997347649 + 0.116470975986383*S) - 0.009520793625590234*S + eta2*(-0.3409769288480959 - 0.8321002363767336*S - 0.13099477081654226*S2) - 0.006383232900211555*S2);
-            double uneqSpin = -0.2962753588645467*(chi1 - 1.*chi2)*eta2*(1. + 1.3993978458830476*eta2) - 0.17100612756133535*(chi1 - 1.*chi2)*eta2*S*(1. + 18.974303741922743*eta2*delta);
+            double noSpin = sqrt(1.-4.*eta)*(0.05511628628738656 - 0.12579599745414977*eta + 2.831411618302815*eta2 - 14.27268643447161*eta3 + 28.3307320191161*eta4);
+            double eqSpin = sqrt(1.-4.*eta)*S*(-0.008692738851491525 + eta*(0.09512553997347649 + 0.116470975986383*S) - 0.009520793625590234*S + eta2*(-0.3409769288480959 - 0.8321002363767336*S - 0.13099477081654226*S2) - 0.006383232900211555*S2);
+            double uneqSpin = -0.2962753588645467*pWF->dchi*eta2*(1. + 1.3993978458830476*eta2) - 0.17100612756133535*pWF->dchi*eta2*S*(1. + 18.974303741922743*eta2*delta);
             total = noSpin + eqSpin + uneqSpin;
             break;
         }
-        default:{XLAL_ERROR_REAL8(XLAL_EINVAL,"Error in IMRPhenomXHM_Insp_Amp_21_iv2: version is not valid. Recommended version is 122018.");}
+        case 122022:{
+            double eta = pWF->eta;
+            double delta = pWF->delta;
+            double sqroot = sqrt(eta);
+            double S = pWF->chiPNHat;
+            double chidiff = pWF->dchi_half;
+            double eta1 = eta;
+            double eta2 = eta1 * eta1;
+            double eta3 = eta1 * eta2;
+            double eta4 = eta1 * eta3;
+            double eta5 = eta1 * eta4;
+            double S1 = S;
+            double S2 = S1 * S1;
+            double chidiff1 = chidiff;
+            double chidiff2 = chidiff1 * chidiff1;
+            total = fabs(chidiff1*eta5*(-2898.9172078672705 + 580.9465034962822*S1 + 22.251142639924076*S2) + delta*(chidiff2*(-18.541685007214625*eta1 + 166.7427445020744*eta2 - 417.5186332459383*eta3) + chidiff1*(41.61457952037761*eta1 - 779.9151607638761*eta2 + 2308.6520892707795*eta3))*sqroot + delta*(11.414934585404561 + 30.883118528233638*eta1 - 260.9979123967537*eta2 + 1046.3187137392433*eta3 - 1556.9475493549746*eta4)*sqroot + delta*S1*(-10.809007068469844*(1.1408749895922659 - 18.140470190766937*eta1 + 368.25127088896744*eta2 - 3064.7291458207815*eta3 + 11501.848278358668*eta4 - 16075.676528787526*eta5) + 1.0088254664333147*(1.2322739396680107 - 192.2461213084741*eta1 + 4257.760834055382*eta2 - 35561.24587952242*eta3 + 130764.22485304279*eta4 - 177907.92440833704*eta5)*S1)*sqroot + delta*(chidiff1*(36.88578491943111*eta1 - 321.2569602623214*eta2 + 748.6659668096737*eta3)*S1 + chidiff1*(-95.42418611585117*eta1 + 1217.338674959742*eta2 - 3656.192371615541*eta3)*S2)*sqroot);
+            break;
+        }
+        default:{XLAL_ERROR_REAL8(XLAL_EINVAL,"Error in IMRPhenomXHM_Insp_Amp_21_iv2: version %i is not valid.", InspAmpFlag);}
     }
     return total;
 }
 
-static double IMRPhenomXHM_Insp_Amp_21_iv3(double eta, double S, double chi1, double chi2, int InspAmpFlag) {
-    UNUSED double total=0, delta=sqrt(1. - 4.*eta),eta2,eta3,eta4,S2,S3;
+static double IMRPhenomXHM_Insp_Amp_21_iv3(IMRPhenomXWaveformStruct *pWF, int InspAmpFlag) {
+    double total=0;
     switch (InspAmpFlag){
         case 122018:{
+            double eta = pWF->eta;
+            double S = pWF->chiPNHat;
+            double delta=sqrt(1.-4.*eta),eta2,S2;
             eta2 = pow(eta,2);
-            eta3 = pow(eta,3);
-            eta4 = pow(eta,4);
             S2 = pow(S,2);
-            S3 = pow(S,3);
-            double noSpin = sqrt(1. - 4.*eta)*(0.059110044024271766 - 0.0024538774422098405*eta + 0.2428578654261086*eta2);
-            double eqSpin = sqrt(1. - 4.*eta)*S*(-0.007044339356171243 - 0.006952154764487417*S + eta2*(-0.016643018304732624 - 0.12702579620537421*S + 0.004623467175906347*S2) - 0.007685497720848461*S2);
-            double uneqSpin = -0.3172310538516028*(chi1 - 1.*chi2)*(1. - 2.9155919835488024*eta2)*eta2 - 0.11975485688200693*(chi1 - 1.*chi2)*eta2*S*(1. + 17.27626751837825*eta2*delta);
+            double noSpin = sqrt(1.-4.*eta)*(0.059110044024271766 - 0.0024538774422098405*eta + 0.2428578654261086*eta2);
+            double eqSpin = sqrt(1.-4.*eta)*S*(-0.007044339356171243 - 0.006952154764487417*S + eta2*(-0.016643018304732624 - 0.12702579620537421*S + 0.004623467175906347*S2) - 0.007685497720848461*S2);
+            double uneqSpin = -0.3172310538516028*pWF->dchi*(1. - 2.9155919835488024*eta2)*eta2 - 0.11975485688200693*pWF->dchi*eta2*S*(1. + 17.27626751837825*eta2*delta);
             total = noSpin + eqSpin + uneqSpin;
             break;
         }
-        default:{XLAL_ERROR_REAL8(XLAL_EINVAL,"Error in IMRPhenomXHM_Insp_Amp_21_iv3: version is not valid. Recommended version is 122018.");}
+        case 122022:{
+            double eta = pWF->eta;
+            double delta = pWF->delta;
+            double sqroot = sqrt(eta);
+            double S = pWF->chiPNHat;
+            double chidiff = pWF->dchi_half;
+            double eta1 = eta;
+            double eta2 = eta1 * eta1;
+            double eta3 = eta1 * eta2;
+            double eta4 = eta1 * eta3;
+            double eta5 = eta1 * eta4;
+            double S1 = S;
+            double S2 = S1 * S1;
+            double chidiff1 = chidiff;
+            total = fabs(chidiff1*eta5*(-2282.9983216879655 + 157.94791186394787*S1 + 16.379731479465033*S2) + chidiff1*delta*(21.935833431534224*eta1 - 460.7130131927895*eta2 + 1350.476411541137*eta3)*sqroot + delta*(5.390240326328237 + 69.01761987509603*eta1 - 568.0027716789259*eta2 + 2435.4098320959706*eta3 - 3914.3390484239667*eta4)*sqroot + chidiff1*delta*(29.731007410186827*eta1 - 372.09609843131386*eta2 + 1034.4897198648962*eta3)*S1*sqroot + delta*S1*(-7.1976397556450715*(0.7603360145475428 - 6.587249958654174*eta1 + 120.87934060776237*eta2 - 635.1835857158857*eta3 + 1109.0598539312573*eta4) - 0.0811847192323969*(7.951454648295709 + 517.4039644814231*eta1 - 9548.970156895082*eta2 + 52586.63520999897*eta3 - 93272.17990295641*eta4)*S1 - 0.28384547935698246*(-0.8870770459576875 + 180.0378964169756*eta1 - 2707.9572896559484*eta2 + 14158.178124971111*eta3 - 24507.800226675925*eta4)*S2)*sqroot);
+            break;
+        }
+        default:{XLAL_ERROR_REAL8(XLAL_EINVAL,"Error in IMRPhenomXHM_Insp_Amp_21_iv3: version %i is not valid.", InspAmpFlag);}
     }
     return total;
 }
 
-static double IMRPhenomXHM_Insp_Amp_33_iv1(double eta, double S, double chi1, double chi2, int InspAmpFlag) {
-    UNUSED double total=0, eta2,eta3,eta4,eta5,S2,S3;
+static double IMRPhenomXHM_Insp_Amp_33_iv1(IMRPhenomXWaveformStruct *pWF, int InspAmpFlag) {
+    double total=0;
     switch (InspAmpFlag){
         case 122018:{
+            double eta = pWF->eta;
+            double S = pWF->chiPNHat;
+            double eta2,S2;
             eta2 = pow(eta,2);
-            eta3 = pow(eta,3);
-            eta4 = pow(eta,4);
-            eta5 = pow(eta,5);
             S2 = pow(S,2);
-            S3 = pow(S,3);
-            double noSpin = (sqrt(1. - 4.*eta)*(-0.056586690934283326 - 0.14374841547279146*eta + 0.5584776628959615*eta2))/(-0.3996185676368123 + eta);
-            double eqSpin = sqrt(1. - 4.*eta)*S*((0.056042044149691175 + 0.12482426029674777*S)*S + eta*(2.1108074577110343 - 1.7827773156978863*S2) + eta2*(-7.657635515668849 - 0.07646730296478217*S + 5.343277927456605*S2));
-            double uneqSpin = 0.45866449225302536*(chi1 - 1.*chi2)*(1. - 9.603750707244906*eta2)*eta2;
+            double noSpin = (sqrt(1.-4.*eta)*(-0.056586690934283326 - 0.14374841547279146*eta + 0.5584776628959615*eta2))/(-0.3996185676368123 + eta);
+            double eqSpin = sqrt(1.-4.*eta)*S*((0.056042044149691175 + 0.12482426029674777*S)*S + eta*(2.1108074577110343 - 1.7827773156978863*S2) + eta2*(-7.657635515668849 - 0.07646730296478217*S + 5.343277927456605*S2));
+            double uneqSpin = 0.45866449225302536*pWF->dchi*(1. - 9.603750707244906*eta2)*eta2;
             total = noSpin + eqSpin + uneqSpin;
             break;
         }
-        default:{XLAL_ERROR_REAL8(XLAL_EINVAL,"Error in IMRPhenomXHM_Insp_Amp_33_iv1: version is not valid. Recommended version is 122018.");}
+        case 122022:{
+            double eta = pWF->eta;
+            double delta = pWF->delta;
+            double sqroot = sqrt(eta);
+            double S = pWF->chiPNHat;
+            double chidiff = pWF->dchi_half;
+            double eta1 = eta;
+            double eta2 = eta1 * eta1;
+            double eta3 = eta1 * eta2;
+            double eta4 = eta1 * eta3;
+            double eta5 = eta1 * eta4;
+            double S1 = S;
+            double S2 = S1 * S1;
+            double chidiff1 = chidiff;
+            total = chidiff1*eta5*(155.1434307076563 + 26.852777193715088*S1 + 1.4157230717300835*S2) + chidiff1*delta*(6.296698171560171*eta1 + 15.81328761563562*eta2 - 141.85538063933927*eta3)*sqroot + delta*(20.94372147101354 + 68.14577638017842*eta1 - 898.470298591732*eta2 + 4598.64854748635*eta3 - 8113.199260593833*eta4)*sqroot + chidiff1*delta*(29.221863857271703*eta1 - 348.1658322276406*eta2 + 965.4670353331536*eta3)*S1*sqroot + delta*S1*(-9.753610761811967*(1.7819678168496158 - 44.07982999150369*eta1 + 750.8933447725581*eta2 - 5652.44754829634*eta3 + 19794.855873435758*eta4 - 26407.40988450443*eta5) + 0.014210376114848208*(-196.97328616330392 + 7264.159472864562*eta1 - 125763.47850622259*eta2 + 1.1458022059130718e6*eta3 - 4.948175330328345e6*eta4 + 7.911048294733888e6*eta5)*S1 - 0.26859293613553986*(-8.029069605349488 + 888.7768796633982*eta1 - 16664.276483466252*eta2 + 128973.72291098491*eta3 - 462437.2690007375*eta4 + 639989.1197424605*eta5)*S2)*sqroot;
+            break;
+        }
+        default:{XLAL_ERROR_REAL8(XLAL_EINVAL,"Error in IMRPhenomXHM_Insp_Amp_33_iv1: version %i is not valid.", InspAmpFlag);}
     }
     return total;
 }
 
-static double IMRPhenomXHM_Insp_Amp_33_iv2(double eta, double S, double chi1, double chi2, int InspAmpFlag) {
-    UNUSED double total=0, eta2,eta3,eta4,eta5,eta6,S2,S3;
+static double IMRPhenomXHM_Insp_Amp_33_iv2(IMRPhenomXWaveformStruct *pWF, int InspAmpFlag) {
+    double total=0;
     switch (InspAmpFlag){
         case 122018:{
+            double eta = pWF->eta;
+            double S = pWF->chiPNHat;
+            double eta2,eta3,eta4,eta5,eta6,S2;
             eta2 = pow(eta,2);
             eta3 = pow(eta,3);
             eta4 = pow(eta,4);
             eta5 = pow(eta,5);
             eta6 = pow(eta,6);
             S2 = pow(S,2);
-            S3 = pow(S,3);
-            double noSpin = sqrt(1. - 4.*eta)*(0.2137734510411439 - 0.7692194209223682*eta + 26.10570221351058*eta2 - 316.0643979123107*eta3 + 2090.9063511488234*eta4 - 6897.3285171507105*eta5 + 8968.893362362503*eta6);
-            double eqSpin = sqrt(1. - 4.*eta)*S*(0.018546836505210842 + 0.05924304311104228*S + eta*(1.6484440612224325 - 0.4683932646001618*S - 2.110311135456494*S2) + 0.10701786057882816*S2 + eta2*(-6.51575737684721 + 1.6692205620001157*S + 8.351789152096782*S2));
-            double uneqSpin = 0.3929315188124088*(chi1 - 1.*chi2)*(1. - 11.289452844364227*eta2)*eta2;
+            double noSpin = sqrt(1.-4.*eta)*(0.2137734510411439 - 0.7692194209223682*eta + 26.10570221351058*eta2 - 316.0643979123107*eta3 + 2090.9063511488234*eta4 - 6897.3285171507105*eta5 + 8968.893362362503*eta6);
+            double eqSpin = sqrt(1.-4.*eta)*S*(0.018546836505210842 + 0.05924304311104228*S + eta*(1.6484440612224325 - 0.4683932646001618*S - 2.110311135456494*S2) + 0.10701786057882816*S2 + eta2*(-6.51575737684721 + 1.6692205620001157*S + 8.351789152096782*S2));
+            double uneqSpin = 0.3929315188124088*pWF->dchi*(1. - 11.289452844364227*eta2)*eta2;
             total = noSpin + eqSpin + uneqSpin;
             break;
         }
-        default:{XLAL_ERROR_REAL8(XLAL_EINVAL,"Error in IMRPhenomXHM_Insp_Amp_33_iv2: version is not valid. Recommended version is 122018.");}
+        case 122022:{
+            double eta = pWF->eta;
+            double delta = pWF->delta;
+            double sqroot = sqrt(eta);
+            double S = pWF->chiPNHat;
+            double chidiff = pWF->dchi_half;
+            double eta1 = eta;
+            double eta2 = eta1 * eta1;
+            double eta3 = eta1 * eta2;
+            double eta4 = eta1 * eta3;
+            double eta5 = eta1 * eta4;
+            double S1 = S;
+            double S2 = S1 * S1;
+            double chidiff1 = chidiff;
+            total = chidiff1*eta5*(161.62678370819597 + 37.141092711336846*S1 - 0.16889712161410445*S2) + chidiff1*delta*(3.4895829486899825*eta1 + 51.07954458810889*eta2 - 249.71072528701757*eta3)*sqroot + delta*(12.501397517602173 + 35.75290806646574*eta1 - 357.6437296928763*eta2 + 1773.8883882162215*eta3 - 3100.2396041211605*eta4)*sqroot + chidiff1*delta*(13.854211287141906*eta1 - 135.54916401086845*eta2 + 327.2467193417936*eta3)*S1*sqroot + delta*S1*(-5.2580116732827085*(1.7794900975289085 - 48.20753331991333*eta1 + 861.1650630146937*eta2 - 6879.681319382729*eta3 + 25678.53964955809*eta4 - 36383.824902258915*eta5) + 0.028627002336747746*(-50.57295946557892 + 734.7581857539398*eta1 - 2287.0465658878725*eta2 + 15062.821881048358*eta3 - 168311.2370167227*eta4 + 454655.37836367317*eta5)*S1 - 0.15528289788512326*(-12.738184090548508 + 1129.44485109116*eta1 - 25091.14888164863*eta2 + 231384.03447562453*eta3 - 953010.5908118751*eta4 + 1.4516597366230418e6*eta5)*S2)*sqroot;
+            break;
+        }
+        default:{XLAL_ERROR_REAL8(XLAL_EINVAL,"Error in IMRPhenomXHM_Insp_Amp_33_iv2: version %i is not valid.", InspAmpFlag);}
     }
     return total;
 }
 
-static double IMRPhenomXHM_Insp_Amp_33_iv3(double eta, double S, double chi1, double chi2, int InspAmpFlag) {
-    UNUSED double total=0, eta2,eta3,eta4,eta5,eta6,S2,S3;
+static double IMRPhenomXHM_Insp_Amp_33_iv3(IMRPhenomXWaveformStruct *pWF, int InspAmpFlag) {
+    double total=0;
     switch (InspAmpFlag){
         case 122018:{
+            double eta = pWF->eta;
+            double S = pWF->chiPNHat;
+            double eta2,eta3,eta4,eta5,eta6,S2;
             eta2 = pow(eta,2);
             eta3 = pow(eta,3);
             eta4 = pow(eta,4);
             eta5 = pow(eta,5);
             eta6 = pow(eta,6);
             S2 = pow(S,2);
-            S3 = pow(S,3);
-            double noSpin = sqrt(1. - 4.*eta)*(0.2363760327127446 + 0.2855410252403732*eta - 10.159877125359897*eta2 + 162.65372389693505*eta3 - 1154.7315106095564*eta4 + 3952.61320206691*eta5 - 5207.67472857814*eta6);
-            double eqSpin = sqrt(1. - 4.*eta)*S*(0.04573095188775319 + 0.048249943132325494*S + eta*(0.15922377052827502 - 0.1837289613228469*S - 0.2834348500565196*S2) + 0.052963737236081304*S2);
-            double uneqSpin = 0.25187274502769835*(chi1 - 1.*chi2)*(1. - 12.172961866410864*eta2)*eta2;
+            double noSpin = sqrt(1.-4.*eta)*(0.2363760327127446 + 0.2855410252403732*eta - 10.159877125359897*eta2 + 162.65372389693505*eta3 - 1154.7315106095564*eta4 + 3952.61320206691*eta5 - 5207.67472857814*eta6);
+            double eqSpin = sqrt(1.-4.*eta)*S*(0.04573095188775319 + 0.048249943132325494*S + eta*(0.15922377052827502 - 0.1837289613228469*S - 0.2834348500565196*S2) + 0.052963737236081304*S2);
+            double uneqSpin = 0.25187274502769835*pWF->dchi*(1. - 12.172961866410864*eta2)*eta2;
             total = noSpin + eqSpin + uneqSpin;
             break;
         }
-        default:{XLAL_ERROR_REAL8(XLAL_EINVAL,"Error in IMRPhenomXHM_Insp_Amp_33_iv3: version is not valid. Recommended version is 122018.");}
+        case 122022:{
+            double eta = pWF->eta;
+            double delta = pWF->delta;
+            double sqroot = sqrt(eta);
+            double S = pWF->chiPNHat;
+            double chidiff = pWF->dchi_half;
+            double eta1 = eta;
+            double eta2 = eta1 * eta1;
+            double eta3 = eta1 * eta2;
+            double eta4 = eta1 * eta3;
+            double eta5 = eta1 * eta4;
+            double eta6 = eta1 * eta5;
+            double eta7 = eta1 * eta6;
+            double S1 = S;
+            double S2 = S1 * S1;
+            double chidiff1 = chidiff;
+            double chidiff2 = chidiff1 * chidiff1;
+            total = chidiff1*delta*(-0.5869777957488564*eta1 + 32.65536124256588*eta2 - 110.10276573567405*eta3) + chidiff1*delta*(3.524800489907584*eta1 - 40.26479860265549*eta2 + 113.77466499598913*eta3)*S1 + delta*S1*(-1.2846335585108297*(0.09991079016763821 + 1.37856806162599*eta1 + 23.26434219690476*eta2 - 34.842921754693386*eta3 - 70.83896459998664*eta4) - 0.03496714763391888*(-0.230558571912664 + 188.38585449575902*eta1 - 3736.1574640444287*eta2 + 22714.70643022915*eta3 - 43221.0453556626*eta4)*S1) + chidiff1*eta7*(2667.3441342894776 + 47.94869769580204*chidiff2 + 793.5988192446642*S1 + 293.89657731755483*S2) + delta*(5.148353856800232 + 148.98231189649468*eta1 - 2774.5868652930294*eta2 + 29052.156454239772*eta3 - 162498.31493332976*eta4 + 460912.76402476896*eta5 - 521279.50781871413*eta6)*sqroot;
+            break;
+        }
+        default:{XLAL_ERROR_REAL8(XLAL_EINVAL,"Error in IMRPhenomXHM_Insp_Amp_33_iv3: version %i is not valid.", InspAmpFlag);}
     }
     return total;
 }
 
-static double IMRPhenomXHM_Insp_Amp_32_iv1(double eta, double S, double chi1, double chi2, int InspAmpFlag) {
-  UNUSED double total=0, delta=sqrt(1. - 4.*eta),eta2,eta3,eta4,eta5,eta6,eta7,eta8,S2,S3,S4;
+static double IMRPhenomXHM_Insp_Amp_32_iv1(IMRPhenomXWaveformStruct *pWF, int InspAmpFlag) {
+  double total=0;
     switch (InspAmpFlag){
         case 122018:{
+            double eta = pWF->eta;
+            double S = pWF->chiPNHat;
+            double delta=sqrt(1.-4.*eta),eta2,eta3,eta4,eta5,eta6,eta8,S2,S3;
             eta2 = pow(eta,2);
             eta3 = pow(eta,3);
             eta4 = pow(eta,4);
             eta5 = pow(eta,5);
             eta6 = pow(eta,6);
-            eta7 = pow(eta,7);
             eta8 = pow(eta,8);
             S2 = pow(S,2);
             S3 = pow(S,3);
-            S4 = pow(S,4);
             double noSpin = sqrt(1. - 3.*eta)*(0.019069933430190773 - 0.19396651989685837*eta + 11.95224600241255*eta2 - 158.90113442757382*eta3 + 1046.65239329071*eta4 - 3476.940285294999*eta5 + 4707.249209858949*eta6);
             double eqSpin = sqrt(1. - 3.*eta)*S*(0.0046910348789512895 + 0.40231360805609434*eta - 0.0038263656140933152*S + 0.018963579407636953*S2 + eta2*(-1.955352354930108 + 2.3753413452420133*S - 0.9085620866763245*S3) + 0.02738043801805805*S3 + eta3*(7.977057990568723 - 7.9259853291789515*S + 0.49784942656123987*S2 + 5.2255665027119145*S3));
-            double uneqSpin = 0.058560321425018165*pow(chi1 - 1.*chi2,2)*(1. - 19.936477485971217*eta2)*eta2 + 1635.4240644598524*(chi1 - 1.*chi2)*eta8*delta + 0.2735219358839411*(chi1 - 1.*chi2)*eta2*S*delta;
+            double uneqSpin = 0.058560321425018165*pow(pWF->dchi,2)*(1. - 19.936477485971217*eta2)*eta2 + 1635.4240644598524*pWF->dchi*eta8*delta + 0.2735219358839411*pWF->dchi*eta2*S*delta;
             total = noSpin + eqSpin + uneqSpin;
             break;
         }
-        default:{XLAL_ERROR_REAL8(XLAL_EINVAL,"Error in IMRPhenomXHM_Insp_Amp_32_iv1: version is not valid. Recommended version is 122018.");}
+        case 122022:{
+            double eta = pWF->eta;
+            double delta = pWF->delta;
+            double sqroot = sqrt(eta);
+            double S = pWF->chiPNHat;
+            double chidiff = pWF->dchi_half;
+            double eta1 = eta;
+            double eta2 = eta1 * eta1;
+            double eta3 = eta1 * eta2;
+            double eta4 = eta1 * eta3;
+            double eta5 = eta1 * eta4;
+            double eta6 = eta1 * eta5;
+            double S1 = S;
+            double chidiff1 = chidiff;
+            double chidiff2 = chidiff1 * chidiff1;
+            total = (chidiff1*delta*(-0.739317114582042*eta1 - 47.473246070362634*eta2 + 278.9717709112207*eta3 - 566.6420939162068*eta4) + chidiff2*(-0.5873680378268906*eta1 + 6.692187014925888*eta2 - 24.37776782232888*eta3 + 23.783684827838247*eta4))*sqroot + (3.2940434453819694 + 4.94285331708559*eta1 - 343.3143244815765*eta2 + 3585.9269057886418*eta3 - 19279.186145681153*eta4 + 51904.91007211022*eta5 - 55436.68857586653*eta6)*sqroot + chidiff1*delta*(12.488240781993923*eta1 - 209.32038774208385*eta2 + 1160.9833883184604*eta3 - 2069.5349737049073*eta4)*S1*sqroot + S1*(0.6343034651912586*(-2.5844888818001737 + 78.98200041834092*eta1 - 1087.6241783616488*eta2 + 7616.234910399297*eta3 - 24776.529123239357*eta4 + 30602.210950069973*eta5) - 0.062088720220899465*(6.5586380356588565 + 36.01386705325694*eta1 - 3124.4712274775407*eta2 + 33822.437731298516*eta3 - 138572.93700180828*eta4 + 198366.10615196894*eta5)*S1)*sqroot;
+            break;
+        }
+        default:{XLAL_ERROR_REAL8(XLAL_EINVAL,"Error in IMRPhenomXHM_Insp_Amp_32_iv1: version %i is not valid.", InspAmpFlag);}
     }
     return total;
 }
 
-static double IMRPhenomXHM_Insp_Amp_32_iv2(double eta, double S, double chi1, double chi2, int InspAmpFlag) {
-    UNUSED double total=0, delta=sqrt(1. - 4.*eta),eta2,eta3,eta4,eta5,eta6,eta7,eta8,S2,S3,S4;
+static double IMRPhenomXHM_Insp_Amp_32_iv2(IMRPhenomXWaveformStruct *pWF, int InspAmpFlag) {
+    double total=0;
     switch (InspAmpFlag){
         case 122018:{
+            double eta = pWF->eta;
+            double S = pWF->chiPNHat;
+            double delta=sqrt(1.-4.*eta),eta2,eta3,eta4,eta8,S2,S3;
             eta2 = pow(eta,2);
             eta3 = pow(eta,3);
             eta4 = pow(eta,4);
-            eta5 = pow(eta,5);
-            eta6 = pow(eta,6);
-            eta7 = pow(eta,7);
             eta8 = pow(eta,8);
             S2 = pow(S,2);
             S3 = pow(S,3);
-            S4 = pow(S,4);
             double noSpin = sqrt(1. - 3.*eta)*(0.024621376891809633 - 0.09692699636236377*eta + 2.7200998230836158*eta2 - 16.160563094841066*eta3 + 32.930430889650836*eta4);
             double eqSpin = sqrt(1. - 3.*eta)*S*(0.008522695567479373 - 1.1104639098529456*eta2 - 0.00362963820787208*S + 0.016978054142418417*S2 + eta*(0.24280554040831698 + 0.15878436411950506*S - 0.1470288177047577*S3) + 0.029465887557447824*S3 + eta3*(4.649438233164449 - 0.7550771176087877*S + 0.3381436950547799*S2 + 2.5663386135613093*S3));
-            double uneqSpin = -0.007061187955941243*pow(chi1 - 1.*chi2,2)*(1. - 2.024701925508361*eta2)*eta2 + 215.06940561269835*(chi1 - 1.*chi2)*eta8*delta + 0.1465612311350642*(chi1 - 1.*chi2)*eta2*S*delta;
+            double uneqSpin = -0.007061187955941243*pow(pWF->dchi,2)*(1. - 2.024701925508361*eta2)*eta2 + 215.06940561269835*pWF->dchi*eta8*delta + 0.1465612311350642*pWF->dchi*eta2*S*delta;
             total = noSpin + eqSpin + uneqSpin;
             break;
         }
-        default:{XLAL_ERROR_REAL8(XLAL_EINVAL,"Error in IMRPhenomXHM_Insp_Amp_32_iv2: version is not valid. Recommended version is 122018.");}
+        case 122022:{
+            double eta = pWF->eta;
+            double delta = pWF->delta;
+            double sqroot = sqrt(eta);
+            double S = pWF->chiPNHat;
+            double chidiff = pWF->dchi_half;
+            double eta1 = eta;
+            double eta2 = eta1 * eta1;
+            double eta3 = eta1 * eta2;
+            double eta4 = eta1 * eta3;
+            double eta5 = eta1 * eta4;
+            double eta6 = eta1 * eta5;
+            double S1 = S;
+            double chidiff1 = chidiff;
+            double chidiff2 = chidiff1 * chidiff1;
+            total = (chidiff2*(-0.03940151060321499*eta1 + 1.9034209537174116*eta2 - 8.78587250202154*eta3) + chidiff1*delta*(-1.704299788495861*eta1 - 4.923510922214181*eta2 + 0.36790005839460627*eta3))*sqroot + (2.2911849711339123 - 5.1846950040514335*eta1 + 60.10368251688146*eta2 - 1139.110227749627*eta3 + 7970.929280907627*eta4 - 25472.73682092519*eta5 + 30950.67053883646*eta6)*sqroot + S1*(0.7718201508695763*(-1.3012906461000349 + 26.432880113146012*eta1 - 186.5001124789369*eta2 + 712.9101229418721*eta3 - 970.2126139442341*eta4) + 0.04832734931068797*(-5.9999628512498315 + 78.98681284391004*eta1 + 1.8360177574514709*eta2 - 2537.636347529708*eta3 + 6858.003573909322*eta4)*S1)*sqroot;
+            break;
+        }
+        default:{XLAL_ERROR_REAL8(XLAL_EINVAL,"Error in IMRPhenomXHM_Insp_Amp_32_iv2: version %i is not valid.", InspAmpFlag);}
     }
     return total;
 }
 
-static double IMRPhenomXHM_Insp_Amp_32_iv3(double eta, double S, double chi1, double chi2, int InspAmpFlag) {
-    UNUSED double total=0, delta=sqrt(1. - 4.*eta),eta2,eta3,eta4,eta5,eta6,eta7,eta8,eta9,S2,S3,S4;
+static double IMRPhenomXHM_Insp_Amp_32_iv3(IMRPhenomXWaveformStruct *pWF, int InspAmpFlag) {
+    double total=0;
     switch (InspAmpFlag){
         case 122018:{
+            double eta = pWF->eta;
+            double S = pWF->chiPNHat;
+            double delta=sqrt(1.-4.*eta),eta2,eta3,eta8,S2,S3;
             eta2 = pow(eta,2);
             eta3 = pow(eta,3);
-            eta4 = pow(eta,4);
-            eta5 = pow(eta,5);
-            eta6 = pow(eta,6);
-            eta7 = pow(eta,7);
             eta8 = pow(eta,8);
-            eta9 = pow(eta,9);
             S2 = pow(S,2);
             S3 = pow(S,3);
-            S4 = pow(S,4);
             double noSpin = (sqrt(1. - 3.*eta)*(-0.006150151041614737 + 0.017454430190035*eta + 0.02620962593739105*eta2 - 0.019043090896351363*eta3))/(-0.2655505633361449 + eta);
             double eqSpin = sqrt(1. - 3.*eta)*S*(0.011073381681404716 + 0.00347699923233349*S + eta*S*(0.05592992411391443 - 0.15666140197050316*S2) + 0.012079324401547036*S2 + eta2*(0.5440307361144313 - 0.008730335213434078*S + 0.04615964369925028*S2 + 0.6703688097531089*S3) + 0.016323101357296865*S3);
-            double uneqSpin = -0.020140175824954427*pow(chi1 - 1.*chi2,2)*(1. - 12.675522774051249*eta2)*eta2 - 417.3604094454253*(chi1 - 1.*chi2)*eta8*delta + 0.10464021067936538*(chi1 - 1.*chi2)*eta2*S*delta;
+            double uneqSpin = -0.020140175824954427*pow(pWF->dchi,2)*(1. - 12.675522774051249*eta2)*eta2 - 417.3604094454253*pWF->dchi*eta8*delta + 0.10464021067936538*pWF->dchi*eta2*S*delta;
             total = noSpin + eqSpin + uneqSpin;
             break;
         }
-        default:{XLAL_ERROR_REAL8(XLAL_EINVAL,"Error in IMRPhenomXHM_Insp_Amp_32_iv3: version is not valid. Recommended version is 122018.");}
+        case 122022:{
+            double eta = pWF->eta;
+            double delta = pWF->delta;
+            double sqroot = sqrt(eta);
+            double S = pWF->chiPNHat;
+            double chidiff = pWF->dchi_half;
+            double eta1 = eta;
+            double eta2 = eta1 * eta1;
+            double eta3 = eta1 * eta2;
+            double eta4 = eta1 * eta3;
+            double eta5 = eta1 * eta4;
+            double eta6 = eta1 * eta5;
+            double S1 = S;
+            double chidiff1 = chidiff;
+            double chidiff2 = chidiff1 * chidiff1;
+            total = (chidiff2*(-0.6358511175987503*eta1 + 5.555088747533164*eta2 - 14.078156877577733*eta3) + chidiff1*delta*(0.23205448591711159*eta1 - 19.46049432345157*eta2 + 36.20685853857613*eta3))*sqroot + (1.1525594672495008 + 7.380126197972549*eta1 - 17.51265776660515*eta2 - 976.9940395257111*eta3 + 8880.536804741967*eta4 - 30849.228936891763*eta5 + 38785.53683146884*eta6)*sqroot + chidiff1*delta*(1.904350804857431*eta1 - 25.565242391371093*eta2 + 80.67120303906654*eta3)*S1*sqroot + S1*(0.785171689871352*(-0.4634745514643032 + 18.70856733065619*eta1 - 167.9231114864569*eta2 + 744.7699462372949*eta3 - 1115.008825153004*eta4) + 0.13469300326662165*(-2.7311391326835133 + 72.17373498208947*eta1 - 483.7040402103785*eta2 + 1136.8367114738041*eta3 - 472.02962341590774*eta4)*S1)*sqroot;
+            break;
+        }
+        default:{XLAL_ERROR_REAL8(XLAL_EINVAL,"Error in IMRPhenomXHM_Insp_Amp_32_iv3: version %i is not valid.", InspAmpFlag);}
     }
     return total;
 }
 
-static double IMRPhenomXHM_Insp_Amp_44_iv1(double eta, double S, double chi1, double chi2, int InspAmpFlag) {
-    UNUSED double total=0, eta2,eta3,eta4,S2,S3;
+static double IMRPhenomXHM_Insp_Amp_44_iv1(IMRPhenomXWaveformStruct *pWF, int InspAmpFlag) {
+    double total=0;
     switch (InspAmpFlag){
         case 122018:{
+            double eta = pWF->eta;
+            double S = pWF->chiPNHat;
+            double eta2,eta3,eta4,S2;
             eta2 = pow(eta,2);
             eta3 = pow(eta,3);
             eta4 = pow(eta,4);
             S2 = pow(S,2);
-            S3 = pow(S,3);
             double noSpin = sqrt(1. - 3.*eta)*(0.06190013067931406 + 0.1928897813606222*eta + 1.9024723168424225*eta2 - 15.988716302668415*eta3 + 35.21461767354364*eta4);
             double eqSpin = sqrt(1. - 3.*eta)*S*(0.011454874900772544 + 0.044702230915643903*S + eta*(0.6600413908621988 + 0.12149520289658673*S - 0.4482406547006759*S2) + 0.07327810908370004*S2 + eta2*(-2.1705970511116486 - 0.6512813450832168*S + 1.1237234702682313*S2));
-            double uneqSpin = 0.4766851579723911*(chi1 - 1.*chi2)*(1. - 15.950025762198988*eta2)*eta2 + 0.127900699645338*pow(chi1 - 1.*chi2,2)*(1. - 15.79329306044842*eta2)*eta2;
+            double uneqSpin = 0.4766851579723911*pWF->dchi*(1. - 15.950025762198988*eta2)*eta2 + 0.127900699645338*pow(pWF->dchi,2)*(1. - 15.79329306044842*eta2)*eta2;
             total = noSpin + eqSpin + uneqSpin;
             break;
         }
-        default:{XLAL_ERROR_REAL8(XLAL_EINVAL,"Error in IMRPhenomXHM_Insp_Amp_44_iv1: version is not valid. Recommended version is 122018.");}
+        case 122022:{
+            double eta = pWF->eta;
+            double delta = pWF->delta;
+            double sqroot = sqrt(eta);
+            double S = pWF->chiPNHat;
+            double chidiff = pWF->dchi_half;
+            double eta1 = eta;
+            double eta2 = eta1 * eta1;
+            double eta3 = eta1 * eta2;
+            double eta4 = eta1 * eta3;
+            double eta5 = eta1 * eta4;
+            double eta6 = eta1 * eta5;
+            double S1 = S;
+            double S2 = S1 * S1;
+            double chidiff1 = chidiff;
+            double chidiff2 = chidiff1 * chidiff1;
+            total = (chidiff1*delta*(0.5697308729057493*eta1 + 8.895576813118867*eta2 - 34.98399465240273*eta3) + chidiff2*(1.6370346538130884*eta1 - 14.597095790380884*eta2 + 33.182723737396294*eta3))*sqroot + (5.2601381002242595 - 3.557926105832778*eta1 - 138.9749850448088*eta2 + 603.7453704122706*eta3 - 923.5495700703648*eta4)*sqroot + S1*(-0.41839636169678796*(5.143510231379954 + 104.62892421207803*eta1 - 4232.508174045782*eta2 + 50694.024801783446*eta3 - 283097.33358214336*eta4 + 758333.2655404843*eta5 - 788783.0559069642*eta6) - 0.05653522061311774*(5.605483124564013 + 694.00652410087*eta1 - 17551.398321516353*eta2 + 165236.6480734229*eta3 - 761661.9645651339*eta4 + 1.7440315410044065e6*eta5 - 1.6010489769238676e6*eta6)*S1 - 0.023693246676754775*(16.437107575918503 - 2911.2154288136217*eta1 + 89338.32554683842*eta2 - 1.0803340811860575e6*eta3 + 6.255666490084672e6*eta4 - 1.7434160932177313e7*eta5 + 1.883460394974573e7*eta6)*S2)*sqroot;
+            break;
+        }
+        default:{XLAL_ERROR_REAL8(XLAL_EINVAL,"Error in IMRPhenomXHM_Insp_Amp_44_iv1: version %i is not valid.", InspAmpFlag);}
     }
     return total;
 }
 
-static double IMRPhenomXHM_Insp_Amp_44_iv2(double eta, double S, double chi1, double chi2, int InspAmpFlag) {
-    UNUSED double total=0, delta=sqrt(1. - 4.*eta),eta2,eta3,eta4,S2,S3;
+static double IMRPhenomXHM_Insp_Amp_44_iv2(IMRPhenomXWaveformStruct *pWF, int InspAmpFlag) {
+    double total=0;
     switch (InspAmpFlag){
         case 122018:{
+            double eta = pWF->eta;
+            double S = pWF->chiPNHat;
+            double delta=sqrt(1.-4.*eta),eta2,eta3,S2,S3;
             eta2 = pow(eta,2);
             eta3 = pow(eta,3);
-            eta4 = pow(eta,4);
             S2 = pow(S,2);
             S3 = pow(S,3);
             double noSpin = 0.08406011695496626 - 0.1469952725049322*eta + 0.2997223283799925*eta2 - 1.2910560244510723*eta3;
             double eqSpin = (0.023924074703897662 + 0.26110236039648027*eta - 1.1536009170220438*eta2)*S + (0.04479727299752669 - 0.1439868858871802*eta + 0.05736387085230215*eta2)*S2 + (0.06028104440131858 - 0.4759412992529712*eta + 1.1090751649419717*eta2)*S3;
-            double uneqSpin = 0.10346324686812074*pow(chi1 - 1.*chi2,2)*(1. - 16.135903382018213*eta2)*eta2 + 0.2648241309154185*(chi1 - 1.*chi2)*eta2*delta;
+            double uneqSpin = 0.10346324686812074*pow(pWF->dchi,2)*(1. - 16.135903382018213*eta2)*eta2 + 0.2648241309154185*pWF->dchi*eta2*delta;
             total = noSpin + eqSpin + uneqSpin;
             break;
         }
-        default:{XLAL_ERROR_REAL8(XLAL_EINVAL,"Error in IMRPhenomXHM_Insp_Amp_44_iv2: version is not valid. Recommended version is 122018.");}
+        case 122022:{
+            double eta = pWF->eta;
+            double delta = pWF->delta;
+            double sqroot = sqrt(eta);
+            double S = pWF->chiPNHat;
+            double chidiff = pWF->dchi_half;
+            double eta1 = eta;
+            double eta2 = eta1 * eta1;
+            double eta3 = eta1 * eta2;
+            double eta4 = eta1 * eta3;
+            double eta5 = eta1 * eta4;
+            double eta6 = eta1 * eta5;
+            double S1 = S;
+            double S2 = S1 * S1;
+            double S3 = S1 * S2;
+            double chidiff1 = chidiff;
+            double chidiff2 = chidiff1 * chidiff1;
+            total = (chidiff2*(-0.8318312659717388*eta1 + 7.6541168007977864*eta2 - 16.648660653220123*eta3) + chidiff1*delta*(2.214478316304753*eta1 - 7.028104574328955*eta2 + 5.56587823143958*eta3))*sqroot + (3.173191054680422 + 6.707695566702527*eta1 - 155.22519772642607*eta2 + 604.0067075996933*eta3 - 876.5048298377644*eta4)*sqroot + chidiff1*delta*(4.749663394334708*eta1 - 42.62996105525792*eta2 + 97.01712147349483*eta3)*S1*sqroot + S1*(-0.2627203100303006*(6.460396349297595 - 52.82425783851536*eta1 - 552.1725902144143*eta2 + 12546.255587592654*eta3 - 81525.50289542897*eta4 + 227254.37897941095*eta5 - 234487.3875219032*eta6) - 0.008424003742397579*(-109.26773035716548 + 15514.571912666677*eta1 - 408022.6805482195*eta2 + 4.620165968920881e6*eta3 - 2.6446950627957724e7*eta4 + 7.539643948937692e7*eta5 - 8.510662871580401e7*eta6)*S1 - 0.008830881730801855*(-37.49992494976597 + 1359.7883958101172*eta1 - 23328.560285901796*eta2 + 260027.4121353132*eta3 - 1.723865744472182e6*eta4 + 5.858455766230802e6*eta5 - 7.756341721552802e6*eta6)*S2 - 0.027167813927224657*(34.281932237450256 - 3312.7658728016568*eta1 + 84126.14531363266*eta2 - 956052.0170024392*eta3 + 5.570748509263883e6*eta4 - 1.6270212243584689e7*eta5 + 1.8855858173287075e7*eta6)*S3)*sqroot;
+            break;
+        }
+        default:{XLAL_ERROR_REAL8(XLAL_EINVAL,"Error in IMRPhenomXHM_Insp_Amp_44_iv2: version %i is not valid.", InspAmpFlag);}
     }
     return total;
 }
 
-static double IMRPhenomXHM_Insp_Amp_44_iv3(double eta, double S, double chi1, double chi2, int InspAmpFlag) {
-    UNUSED double total=0, delta=sqrt(1. - 4.*eta),eta2,eta3,eta4,eta5,S2,S3;
+static double IMRPhenomXHM_Insp_Amp_44_iv3(IMRPhenomXWaveformStruct *pWF, int InspAmpFlag) {
+    double total=0;
     switch (InspAmpFlag){
         case 122018:{
+            double eta = pWF->eta;
+            double S = pWF->chiPNHat;
+            double delta=sqrt(1.-4.*eta),eta2,eta3,eta4,eta5,S2;
             eta2 = pow(eta,2);
             eta3 = pow(eta,3);
             eta4 = pow(eta,4);
             eta5 = pow(eta,5);
             S2 = pow(S,2);
-            S3 = pow(S,3);
             double noSpin = 0.08212436946985402 - 0.025332770704783136*eta - 3.2466088293309885*eta2 + 28.404235115663706*eta3 - 111.36325359782991*eta4 + 157.05954559045156*eta5;
             double eqSpin = S*(0.03488890057062679 + 0.039491331923244756*S + eta*(-0.08968833480313292 - 0.12754920943544915*S - 0.11199012099701576*S2) + 0.034468577523793176*S2);
-            double uneqSpin = 0.2062291124580944*(chi1 - 1.*chi2)*eta2*delta;
+            double uneqSpin = 0.2062291124580944*pWF->dchi*eta2*delta;
             total = noSpin + eqSpin + uneqSpin;
             break;
         }
-        default:{XLAL_ERROR_REAL8(XLAL_EINVAL,"Error in IMRPhenomXHM_Insp_Amp_44_iv3: version is not valid. Recommended version is 122018.");}
+        case 122022:{
+            double eta = pWF->eta;
+            double delta = pWF->delta;
+            double sqroot = sqrt(eta);
+            double S = pWF->chiPNHat;
+            double chidiff = pWF->dchi_half;
+            double eta1 = eta;
+            double eta2 = eta1 * eta1;
+            double eta3 = eta1 * eta2;
+            double eta4 = eta1 * eta3;
+            double eta5 = eta1 * eta4;
+            double eta6 = eta1 * eta5;
+            double S1 = S;
+            double S2 = S1 * S1;
+            double chidiff1 = chidiff;
+            double chidiff2 = chidiff1 * chidiff1;
+            total = (chidiff1*delta*(1.4739380748149558*eta1 + 0.06541707987699942*eta2 - 9.473290540936633*eta3) + chidiff2*(-0.3640838331639651*eta1 + 3.7369795937033756*eta2 - 8.709159662885131*eta3))*sqroot + (1.7335503724888923 + 12.656614578053683*eta1 - 139.6610487470118*eta2 + 456.78649322753824*eta3 - 599.2709938848282*eta4)*sqroot + chidiff1*delta*(2.3532739003216254*eta1 - 21.37216554136868*eta2 + 53.35003268489743*eta3)*S1*sqroot + S1*(-0.15782329022461472*(6.0309399412954345 - 229.16361598098678*eta1 + 3777.477006415653*eta2 - 31109.307191210424*eta3 + 139319.8239886073*eta4 - 324891.4001578353*eta5 + 307714.3954026392*eta6) - 0.03050157254864058*(4.232861441291087 + 1609.4251694451375*eta1 - 51213.27604422822*eta2 + 612317.1751155312*eta3 - 3.5589766538499263e6*eta4 + 1.0147654212772278e7*eta5 - 1.138861230369246e7*eta6)*S1 - 0.026407497690308382*(-17.184685557542196 + 744.4743953122965*eta1 - 10494.512487701073*eta2 + 66150.52694069289*eta3 - 184787.79377504133*eta4 + 148102.4257785174*eta5 + 128167.89151782403*eta6)*S2)*sqroot;
+            break;
+        }
+        default:{XLAL_ERROR_REAL8(XLAL_EINVAL,"Error in IMRPhenomXHM_Insp_Amp_44_iv3: version %i is not valid.", InspAmpFlag);}
     }
     return total;
 }
 
+/* End of Amp Parameter Space Fits */
+
 
 /***********************************************/
 /*     Pseudo PN Amplitude Coefficients    */
@@ -437,37 +667,29 @@ static double IMRPhenomXHM_Inspiral_Amp_rho3(double v1, double v2, double v3, IM
 //Return the Fourier Domain Post-Newtonian ansatz up to 3PN without the pseudoPN terms for a particular frequency
 static double IMRPhenomXHM_Inspiral_PNAmp_Ansatz(IMRPhenomX_UsefulPowers *powers_of_Mf, IMRPhenomXHMWaveformStruct *pWFHM, IMRPhenomXHMAmpCoefficients *pAmp){
 
-  // The 21 mode is special, is not a power series
-  if(pWFHM->useFAmpPN==1){
+    // The 21 mode is special, is not a power series
+    if(pWFHM->useFAmpPN==1){
     return IMRPhenomXHM_Inspiral_PNAmp_21Ansatz(powers_of_Mf, pWFHM, pAmp);
-  }
+    }
 
-   //This returns the amplitude strain rescaled with the prefactor of the 22 mode: divided by sqrt(2*eta/3.)/pi^(1/6)
-  double complex CpnAmp;
-  double pnAmp;
-  int InsAmpFlag = pWFHM->IMRPhenomXHMInspiralAmpFitsVersion;
-  switch(InsAmpFlag)
-  {
-    case 122018:
-    {
-      CpnAmp = (pAmp->pnInitial
+    //This returns the amplitude strain rescaled with the prefactor of the 22 mode: divided by sqrt(2*eta/3.)/pi^(1/6)*Mf^(-7/6)
+    double pnAmp;
+    pnAmp = cabs(pAmp->pnInitial
         + powers_of_Mf->one_third    * pAmp->pnOneThird
         + powers_of_Mf->two_thirds   * pAmp->pnTwoThirds
         + powers_of_Mf->itself       * pAmp->pnThreeThirds
         + powers_of_Mf->four_thirds  * pAmp->pnFourThirds
         + powers_of_Mf->five_thirds  * pAmp->pnFiveThirds
         + powers_of_Mf->two          * pAmp->pnSixThirds
-      );
-      pnAmp = (pAmp->PNglobalfactor)*cabs(CpnAmp);
-      break;
+    );// * (pAmp->PNglobalfactor); // Added
+    if (pAmp->InspRescaleFactor == 0){
+        pnAmp *= pAmp->PNglobalfactor * powers_of_Mf->m_seven_sixths * pWFHM->ampNorm;
     }
-    default :
-    {
-        XLAL_ERROR_REAL8(XLAL_EINVAL, "Error in IMRPhenomXHM_Inspiral_PNAmp_Ansatz: IMRPhenomXInspiralAmpVersion is not valid. Recommended version is 122018.\n");
+    else if (pAmp->InspRescaleFactor == 1){
+       pnAmp *= pAmp->PNglobalfactor;
     }
-  }
 
-  return pnAmp;
+    return pnAmp;
 }
 
 //Return the 21 mode Fourier Domain Post-Newtonian ansatz up to 3PN without the pseudoPN terms for a particular frequency
@@ -476,7 +698,7 @@ static double IMRPhenomXHM_Inspiral_PNAmp_21Ansatz(IMRPhenomX_UsefulPowers *powe
   double complex CpnAmpTD; //This is not the real strain of the lm mode. It is the strain rescaled with the prefactor of the 22 mode: divided by sqrt(2*eta/3.)/pi^(1/6)
   double pnAmp, XdotT4, x_to_m_one_four, two_to_m_one_sixths = 0.8908987181403393, three_to_m_one_second = 0.5773502691896257;
   x_to_m_one_four = two_to_m_one_sixths * powers_of_lalpiHM.m_one_sixth * powers_of_Mf->m_one_sixth;
-  int InsAmpFlag = pWFHM->IMRPhenomXHMInspiralAmpFitsVersion;
+  int InsAmpFlag = pWFHM->IMRPhenomXHMInspiralAmpFreqsVersion;
   switch(InsAmpFlag)
   {
     case 122018:
@@ -503,8 +725,12 @@ static double IMRPhenomXHM_Inspiral_PNAmp_21Ansatz(IMRPhenomX_UsefulPowers *powe
       + powers_of_Mf->eight_thirds * powers_of_Mf->eight_thirds * powers_of_Mf->one_third  * pAmp->xdot85;
 
       // Perform the SPA, multiply time-domain by the phasing factor
-      pnAmp = 2. * powers_of_lalpiHM.sqrt  * three_to_m_one_second  * cabs(CpnAmpTD) * x_to_m_one_four / sqrt(XdotT4) /powers_of_Mf->m_seven_sixths/pWFHM->ampNorm;
-      break;
+      pnAmp = 2. * powers_of_lalpiHM.sqrt * three_to_m_one_second  * cabs(CpnAmpTD) * x_to_m_one_four / sqrt(XdotT4);///powers_of_Mf->m_seven_sixths/pWFHM->ampNorm;//Added last two
+      if (pAmp->InspRescaleFactor != 0){
+          pnAmp /= RescaleFactor(powers_of_Mf, pAmp, pAmp->InspRescaleFactor);
+      }
+
+     break;
     }
     default:{XLAL_ERROR_REAL8(XLAL_EINVAL, "Error in IMRPhenomXHM_Inspiral_PNAmp_Ansatz: IMRPhenomXInspiralAmpVersion is not valid. Recommended version is 122018.\n");}
   }
@@ -516,21 +742,34 @@ static double IMRPhenomXHM_Inspiral_PNAmp_21Ansatz(IMRPhenomX_UsefulPowers *powe
 static double IMRPhenomXHM_Inspiral_Amp_Ansatz(IMRPhenomX_UsefulPowers *powers_of_Mf, IMRPhenomXHMWaveformStruct *pWFHM, IMRPhenomXHMAmpCoefficients *pAmp)
 {
     double InspAmp; //This is the amplitude strain rescaled with the prefactor of the 22 mode: divided by [sqrt(2*eta/3.)/pi^(1/6) * f^(-7/6)]
-    int InsAmpFlag = pWFHM->IMRPhenomXHMInspiralAmpFitsVersion;
-    switch(InsAmpFlag)
-    {
-        case 122018:
-        {
-            InspAmp = IMRPhenomXHM_Inspiral_PNAmp_Ansatz(powers_of_Mf, pWFHM, pAmp)
+    double pseudoterms = 0.;
+    if(pWFHM->IMRPhenomXHMInspiralAmpFreqsVersion == 122018){
+        INT2 tmp = pAmp->InspRescaleFactor;
+        pAmp->InspRescaleFactor = 1;
+        InspAmp = IMRPhenomXHM_Inspiral_PNAmp_Ansatz(powers_of_Mf, pWFHM, pAmp)
             + powers_of_Mf->seven_thirds / pAmp->fcutInsp_seven_thirds * pAmp->rho1
             + powers_of_Mf->eight_thirds / pAmp->fcutInsp_eight_thirds * pAmp->rho2
             + powers_of_Mf->three        / pAmp->fcutInsp_three * pAmp->rho3
             ;
-            break;
+        pAmp->InspRescaleFactor = tmp;
+        if (pAmp->InspRescaleFactor == 0){
+            InspAmp *= powers_of_Mf->m_seven_sixths * pWFHM->ampNorm;
         }
-        default:{XLAL_ERROR_REAL8(XLAL_EINVAL, "Error in IMRPhenomXHM_Inspiral_Amp_Ansatz: IMRPhenomXInspiralAmpVersion is not valid. Recommended version is 2018. \n");}
     }
-    return InspAmp;
+    else{
+        /* New release. FIXME: improve how the ansatz is built */
+        InspAmp = IMRPhenomXHM_Inspiral_PNAmp_Ansatz(powers_of_Mf, pWFHM, pAmp);
+        pseudoterms = powers_of_Mf->seven_thirds / pAmp->fcutInsp_seven_thirds * pAmp->InspiralCoefficient[0]
+                + powers_of_Mf->eight_thirds / pAmp->fcutInsp_eight_thirds * pAmp->InspiralCoefficient[1]
+                + powers_of_Mf->three        / pAmp->fcutInsp_three * pAmp->InspiralCoefficient[2];
+        pseudoterms *= powers_of_Mf->m_seven_sixths * pAmp->PNdominant;
+        InspAmp += pseudoterms;
+        if (pAmp->InspRescaleFactor != 0){
+            InspAmp /= RescaleFactor(powers_of_Mf, pAmp, pAmp->InspRescaleFactor);
+        }
+    }        
+
+    return InspAmp ;
 }
 
 /* Numerical derivative of the inspiral (4th order finite differences)
@@ -599,8 +838,109 @@ int WavyPoints(double p1, double p2, double p3){
     }
 }
 
+void IMRPhenomXHM_Get_Inspiral_Amp_Coefficients(IMRPhenomXHMAmpCoefficients *pAmp, IMRPhenomXHMWaveformStruct *pWFHM, IMRPhenomXWaveformStruct *pWF22){
+
+    // Get CollocationPointsFreqsAmplitudeInsp and CollocationPointsValuesAmplitudeInsp
+    IMRPhenomX_UsefulPowers *powers_of_Mf_inspcollpoints = (IMRPhenomX_UsefulPowers *)XLALMalloc((pWFHM->nCollocPtsInspAmp + 1) * sizeof(IMRPhenomX_UsefulPowers));
+    IMRPhenomXHM_Inspiral_Amp_CollocationPoints(pAmp, pWFHM, pWF22);
+
+    for(UINT2 i = 0; i < pWFHM->nCollocPtsInspAmp; i++){
+        int status = IMRPhenomX_Initialize_Powers(&(powers_of_Mf_inspcollpoints[i]),  pAmp->CollocationPointsFreqsAmplitudeInsp[i]);
+        if(status != XLAL_SUCCESS)
+            XLALPrintError("IMRPhenomXHM_Get_Inspiral_Amp_Coefficients failed for Mf, initial_status=%d",status);
+    }
+    int status = IMRPhenomX_Initialize_Powers(&(powers_of_Mf_inspcollpoints[pWFHM->nCollocPtsInspAmp]),  pAmp->fAmpMatchIN);
+    if(status != XLAL_SUCCESS)
+        XLALPrintError("IMRPhenomXHM_Get_Inspiral_Amp_Coefficients failed for Mf, initial_status=%d",status);
+    pAmp->fcutInsp_seven_thirds = powers_of_Mf_inspcollpoints[pWFHM->nCollocPtsInspAmp].seven_thirds;
+    pAmp->fcutInsp_eight_thirds = powers_of_Mf_inspcollpoints[pWFHM->nCollocPtsInspAmp].eight_thirds;
+    pAmp->fcutInsp_three = powers_of_Mf_inspcollpoints[pWFHM->nCollocPtsInspAmp].three;
+
+
+    // Do Vetos? set final pWFHM->IMRPhenomXHMInspiralAmpVersion
+
+    // Get PN values at collocation points frequencies
+    for (INT4 i=0; i < pWFHM->nCollocPtsInspAmp; i++){
+        pAmp->PNAmplitudeInsp[i] = IMRPhenomXHM_Inspiral_PNAmp_Ansatz(&(powers_of_Mf_inspcollpoints[i]), pWFHM, pAmp);
+    }
+
+    IMRPhenomXHM_Inspiral_Amp_Coefficients(pAmp, powers_of_Mf_inspcollpoints, pWFHM);
+
+    LALFree(powers_of_Mf_inspcollpoints);
+}
+
+static void IMRPhenomXHM_Inspiral_Amp_CollocationPoints(IMRPhenomXHMAmpCoefficients *pAmp, IMRPhenomXHMWaveformStruct *pWFHM, IMRPhenomXWaveformStruct *pWF22){
+    switch(pWFHM->IMRPhenomXHMInspiralAmpFreqsVersion){
+        case 122022:
+        case 102021:{
+            pAmp->CollocationPointsFreqsAmplitudeInsp[0] = 0.5  * pAmp->fAmpMatchIN;
+            pAmp->CollocationPointsFreqsAmplitudeInsp[1] = 0.75 * pAmp->fAmpMatchIN;
+            pAmp->CollocationPointsFreqsAmplitudeInsp[2] = pAmp->fAmpMatchIN;
+            break;
+        }
+        // FIXME: Add cases for equispaced, Chebyshev
+        default: {XLAL_ERROR_VOID(XLAL_EDOM, "Error in IMRPhenomXHM_Inspiral_CollocationPoints: IMRPhenomXHMInspiralAmpFreqsVersion = %i is not valid. Recommneded version is 102021.\n", pWFHM->IMRPhenomXHMInspiralAmpFreqsVersion);}
+    }
+    for(UINT2 i = 0; i < pWFHM->nCollocPtsInspAmp; i++){
+        pAmp->CollocationPointsValuesAmplitudeInsp[i] = fabs(pAmp->InspiralAmpFits[pWFHM->modeInt * pWFHM->nCollocPtsInspAmp + i](pWF22, pWFHM->IMRPhenomXHMInspiralAmpFitsVersion));
+    }
+    
+    if (pWFHM->InspiralAmpVeto == 1){
+        pWFHM->IMRPhenomXHMInspiralAmpVersion = 13;
+    }
+}
+
+static void IMRPhenomXHM_Inspiral_Amp_Coefficients(IMRPhenomXHMAmpCoefficients *pAmp, IMRPhenomX_UsefulPowers *powers_of_Mf_inspcollpoints, IMRPhenomXHMWaveformStruct *pWFHM){
+
+    for (UINT2 i = 0; i < N_MAX_COEFFICIENTS_AMPLITUDE_INS; i++){
+        pAmp->InspiralCoefficient[i] = 0;
+    }
+
+    IMRPhenomX_UsefulPowers *powers_of_f1 = &(powers_of_Mf_inspcollpoints[0]);
+    IMRPhenomX_UsefulPowers *powers_of_f2 = &(powers_of_Mf_inspcollpoints[1]);
+    IMRPhenomX_UsefulPowers *powers_of_f3 = &(powers_of_Mf_inspcollpoints[2]);
+    IMRPhenomX_UsefulPowers *powers_of_finsp = &(powers_of_Mf_inspcollpoints[3]);
 
+    REAL8 v1 = (pAmp->CollocationPointsValuesAmplitudeInsp[0] - pAmp->PNAmplitudeInsp[0]) / pAmp->PNdominant / powers_of_f1->m_seven_sixths;
+    REAL8 v2 = (pAmp->CollocationPointsValuesAmplitudeInsp[1] - pAmp->PNAmplitudeInsp[1]) / pAmp->PNdominant / powers_of_f2->m_seven_sixths;
+    REAL8 v3 = (pAmp->CollocationPointsValuesAmplitudeInsp[2] - pAmp->PNAmplitudeInsp[2]) / pAmp->PNdominant / powers_of_f3->m_seven_sixths;
 
+    switch(pWFHM->IMRPhenomXHMInspiralAmpVersion){
+        case 1:{
+            pAmp->InspiralCoefficient[0] = (powers_of_finsp->seven_thirds*v1)/powers_of_f1->seven_thirds;
+            break;
+        }
+        case 2:{
+            pAmp->InspiralCoefficient[0] = (powers_of_finsp->seven_thirds*v2)/powers_of_f2->seven_thirds;
+            break;
+        }
+        case 3:{
+            pAmp->InspiralCoefficient[0] = (powers_of_finsp->seven_thirds*v3)/powers_of_f3->seven_thirds;
+            break;
+        }
+        case 12:{
+            pAmp->InspiralCoefficient[0] = (powers_of_finsp->seven_thirds*(-(powers_of_f2->eight_thirds*v1) + powers_of_f1->eight_thirds*v2))/(powers_of_f1->seven_thirds*(powers_of_f1->one_third - powers_of_f2->one_third)*powers_of_f2->seven_thirds);
+            pAmp->InspiralCoefficient[1] = (powers_of_finsp->eight_thirds*(powers_of_f1->m_seven_thirds*v1 - powers_of_f2->m_seven_thirds*v2))/(powers_of_f1->one_third - powers_of_f2->one_third);
+            break;
+        }
+        case 13:{
+            pAmp->InspiralCoefficient[0] = (powers_of_finsp->seven_thirds*(-(powers_of_f3->eight_thirds*v1) + powers_of_f1->eight_thirds*v3))/(powers_of_f1->seven_thirds*(powers_of_f1->one_third - powers_of_f3->one_third)*powers_of_f3->seven_thirds);
+            pAmp->InspiralCoefficient[1] = (powers_of_finsp->eight_thirds*(powers_of_f1->m_seven_thirds*v1 - powers_of_f3->m_seven_thirds*v3))/(powers_of_f1->one_third - powers_of_f3->one_third);
+            break;
+        }
+        case 23:{
+            pAmp->InspiralCoefficient[0] = (powers_of_finsp->seven_thirds*(-(powers_of_f3->eight_thirds*v2) + powers_of_f2->eight_thirds*v3))/(powers_of_f2->seven_thirds*(powers_of_f2->one_third - powers_of_f3->one_third)*powers_of_f3->seven_thirds);
+            pAmp->InspiralCoefficient[1] = (powers_of_finsp->eight_thirds*(powers_of_f1->m_seven_thirds*v1 - powers_of_f3->m_seven_thirds*v3))/(powers_of_f1->one_third - powers_of_f3->one_third);
+            break;
+        }
+        case 123:{
+            pAmp->InspiralCoefficient[0] = (powers_of_finsp->seven_thirds*(-(powers_of_f1->three*powers_of_f3->eight_thirds*v2) + powers_of_f1->eight_thirds*powers_of_f3->three*v2 + powers_of_f2->three*(powers_of_f3->eight_thirds*v1 - powers_of_f1->eight_thirds*v3) + powers_of_f2->eight_thirds*(-(powers_of_f3->three*v1) + powers_of_f1->three*v3)))/(powers_of_f1->seven_thirds*(powers_of_f1->one_third - powers_of_f2->one_third)*powers_of_f2->seven_thirds*(powers_of_f1->one_third - powers_of_f3->one_third)*(powers_of_f2->one_third - powers_of_f3->one_third)*powers_of_f3->seven_thirds);
+            pAmp->InspiralCoefficient[1] = (powers_of_finsp->eight_thirds*(powers_of_f1->three*powers_of_f3->seven_thirds*v2 - powers_of_f1->seven_thirds*powers_of_f3->three*v2 + powers_of_f2->three*(-(powers_of_f3->seven_thirds*v1) + powers_of_f1->seven_thirds*v3) + powers_of_f2->seven_thirds*(powers_of_f3->three*v1 - powers_of_f1->three*v3)))/(powers_of_f1->seven_thirds*(powers_of_f1->one_third - powers_of_f2->one_third)*powers_of_f2->seven_thirds*(powers_of_f1->one_third - powers_of_f3->one_third)*(powers_of_f2->one_third - powers_of_f3->one_third)*powers_of_f3->seven_thirds);
+            pAmp->InspiralCoefficient[2] = (powers_of_finsp->three*(powers_of_f1->seven_thirds*(-powers_of_f1->one_third + powers_of_f3->one_third)*powers_of_f3->seven_thirds*v2 + powers_of_f2->seven_thirds*(-(powers_of_f3->eight_thirds*v1) + powers_of_f1->eight_thirds*v3) + powers_of_f2->eight_thirds*(powers_of_f3->seven_thirds*v1 - powers_of_f1->seven_thirds*v3)))/(powers_of_f1->seven_thirds*(powers_of_f1->one_third - powers_of_f2->one_third)*powers_of_f2->seven_thirds*(powers_of_f1->one_third - powers_of_f3->one_third)*(powers_of_f2->one_third - powers_of_f3->one_third)*powers_of_f3->seven_thirds);
+            break;
+        }
+    }
+}
 /*************************************/
 /*                                   */
 /*              PHASE                */
@@ -611,19 +951,23 @@ int WavyPoints(double p1, double p2, double p3){
 
 // Below we give paramater-space fits for the weighted difference between each mode's phase and the 22-phase: phi_lm-m/2 phi_22(2/m f), see Eqs. (4.10-4.12)
 
-static double IMRPhenomXHM_Insp_Phase_21_lambda(double eta, double S, double chi1, double chi2, int InspPhaseFlag) {
-    UNUSED double total,eta2,eta3,eta4,eta5,S2,S3;
+/* Start of Phase Parameter Space Fits */
+
+static double IMRPhenomXHM_Insp_Phase_21_lambda(IMRPhenomXWaveformStruct *pWF, int InspPhaseFlag) {
+    double total;
     switch (InspPhaseFlag){
         case 122019:{
+            double eta = pWF->eta;
+            double S = pWF->STotR;
+            double eta2,eta3,eta4,eta5,S2;
             eta2 = pow(eta,2);
             eta3 = pow(eta,3);
             eta4 = pow(eta,4);
             eta5 = pow(eta,5);
             S2 = pow(S,2);
-            S3 = pow(S,3);
             double noSpin = 13.664473636545068 - 170.08866400251395*eta + 3535.657736681598*eta2 - 26847.690494515424*eta3 + 96463.68163125668*eta4 - 133820.89317471132*eta5;
             double eqSpin = (S*(18.52571430563905 - 41.55066592130464*S + eta3*(83493.24265292779 + 16501.749243703132*S - 149700.4915210766*S2) + eta*(3642.5891077598003 + 1198.4163078715173*S - 6961.484805326852*S2) + 33.8697137964237*S2 + eta2*(-35031.361998480075 - 7233.191207000735*S + 62149.00902591944*S2)))/(6.880288191574696 + 1.*S);
-            double uneqSpin = -134.27742343186577*(chi1 - 1.*chi2)*sqrt(1. - 4.*eta)*eta2;
+            double uneqSpin = -134.27742343186577*pWF->dchi*sqrt(1.-4.*eta)*eta2;
             total = noSpin + eqSpin + uneqSpin;
             break;
         }
@@ -632,16 +976,19 @@ static double IMRPhenomXHM_Insp_Phase_21_lambda(double eta, double S, double chi
     return total;
 }
 
-static double IMRPhenomXHM_Insp_Phase_33_lambda(double eta, double S, double chi1, double chi2, int InspPhaseFlag) {
-    double total=0,eta2,eta3;
-    double delta=sqrt(1. - 4.*eta);
+static double IMRPhenomXHM_Insp_Phase_33_lambda(IMRPhenomXWaveformStruct *pWF, int InspPhaseFlag) {
+    double total=0;
     switch (InspPhaseFlag){
         case 122019:{
+            double eta = pWF->eta;
+            double S = pWF->STotR;
+            double delta=sqrt(1.-4.*eta);
+            double eta2,eta3;
             eta2 = pow(eta,2);
             eta3 = eta2*eta;
             double noSpin = 4.1138398568400705 + 9.772510519809892*eta - 103.92956504520747*eta2 + 242.3428625556764*eta3;
             double eqSpin = ((-0.13253553909611435 + 26.644159828590055*eta - 105.09339163109497*eta2)*S)/(1. + 0.11322426762297967*S);
-            double uneqSpin = -19.705359163581168*(chi1 - 1.*chi2)*eta2*delta;
+            double uneqSpin = -19.705359163581168*pWF->dchi*eta2*delta;
             total = noSpin + eqSpin + uneqSpin;
             break;
         }
@@ -650,10 +997,13 @@ static double IMRPhenomXHM_Insp_Phase_33_lambda(double eta, double S, double chi
     return total;
 }
 
-static double IMRPhenomXHM_Insp_Phase_32_lambda(double eta, double S, double chi1, double chi2, int InspPhaseFlag) {
-    double total,eta2,eta3,eta4,S2,S3,S4;
+static double IMRPhenomXHM_Insp_Phase_32_lambda(IMRPhenomXWaveformStruct *pWF, int InspPhaseFlag) {
+    double total;
     switch (InspPhaseFlag){
         case 122019:{
+            double eta = pWF->eta;
+            double S = pWF->STotR;
+            double eta2,eta3,eta4,S2,S3,S4;
             eta2 = pow(eta,2);
             eta3 = pow(eta,3);
             eta4 = pow(eta,4);
@@ -662,7 +1012,7 @@ static double IMRPhenomXHM_Insp_Phase_32_lambda(double eta, double S, double chi
             S4 = pow(S,4);
             double noSpin = (9.913819875501506 + 18.424900617803107*eta - 574.8672384388947*eta2 + 2671.7813055097877*eta3 - 6244.001932443913*eta4)/(1. - 0.9103118343073325*eta);
             double eqSpin = (-4.367632806613781 + 245.06757304950986*eta - 2233.9319708029775*eta2 + 5894.355429022858*eta3)*S + (-1.375112297530783 - 1876.760129419146*eta + 17608.172965575013*eta2 - 40928.07304790013*eta3)*S2 + (-1.28324755577382 - 138.36970336658558*eta + 708.1455154504333*eta2 - 273.23750933544176*eta3)*S3 + (1.8403161863444328 + 2009.7361967331492*eta - 18636.271414571278*eta2 + 42379.205045791656*eta3)*S4;
-            double uneqSpin = (chi1 - 1.*chi2)*sqrt(1. - 4.*eta)*eta2*(-105.34550407768225 - 1566.1242344157668*chi1*eta + 1566.1242344157668*chi2*eta + 2155.472229664981*eta*S);
+            double uneqSpin = pWF->dchi*sqrt(1.-4.*eta)*eta2*(-105.34550407768225 - 1566.1242344157668*pWF->chi1L*eta + 1566.1242344157668*pWF->chi2L*eta + 2155.472229664981*eta*S);
             total = noSpin + eqSpin + uneqSpin;
             break;
         }
@@ -672,10 +1022,13 @@ static double IMRPhenomXHM_Insp_Phase_32_lambda(double eta, double S, double chi
 }
 
 
-static double IMRPhenomXHM_Insp_Phase_44_lambda(double eta, double S, double chi1, double chi2, int InspPhaseFlag) {
-    double total,eta2,eta3,eta4,eta5,S2;
+static double IMRPhenomXHM_Insp_Phase_44_lambda(IMRPhenomXWaveformStruct *pWF, int InspPhaseFlag) {
+    double total;
     switch (InspPhaseFlag){
         case 122019:{
+            double eta = pWF->eta;
+            double S = pWF->STotR;
+            double eta2,eta3,eta4,eta5,S2;
             eta2 = pow(eta,2);
             eta3 = pow(eta,3);
             eta4 = pow(eta,4);
@@ -683,7 +1036,7 @@ static double IMRPhenomXHM_Insp_Phase_44_lambda(double eta, double S, double chi
             S2 = pow(S,2);
             double noSpin = 5.254484747463392 - 21.277760168559862*eta + 160.43721442910618*eta2 - 1162.954360723399*eta3 + 1685.5912722190276*eta4 - 1538.6661348106031*eta5;
             double eqSpin = (0.007067861615983771 - 10.945895160727437*eta + 246.8787141453734*eta2 - 810.7773268493444*eta3)*S + (0.17447830920234977 + 4.530539154777984*eta - 176.4987316167203*eta2 + 621.6920322846844*eta3)*S2;
-            double uneqSpin = -8.384066369867833*(chi1 - 1.*chi2)*sqrt(1. - 4.*eta)*eta2;
+            double uneqSpin = -8.384066369867833*pWF->dchi*sqrt(1.-4.*eta)*eta2;
             total = noSpin + eqSpin + uneqSpin;
             break;
         }
@@ -692,6 +1045,8 @@ static double IMRPhenomXHM_Insp_Phase_44_lambda(double eta, double S, double chi
     return total;
 }
 
+/* End of Phase Parameter Space Fits */
+
 // Returns linear-in-f term coming from the complex part of each mode's amplitude that will be added to the orbital phase, this is an expansion of Eq. (4.9) truncated at linear order
 static double IMRPhenomXHM_Insp_Phase_LambdaPN(double eta, int modeInt){
 
@@ -737,7 +1092,7 @@ static double IMRPhenomXHM_Inspiral_Phase_AnsatzInt(double Mf, IMRPhenomX_Useful
 {
     //compute the orbital phase by laoding the rescaled phenX coefficients
     double philm=0.;
-    double freqs[]={powers_of_Mf->m_five_thirds,powers_of_Mf->m_four_thirds,powers_of_Mf->m_one,powers_of_Mf->m_two_thirds,powers_of_Mf->m_one_third,1.,powers_of_Mf->one_third,powers_of_Mf->two_thirds, Mf, powers_of_Mf->four_thirds, powers_of_Mf->five_thirds, powers_of_Mf->two,powers_of_Mf->seven_thirds};
+    double freqs[N_MAX_COEFFICIENTS_PHASE_INS]={powers_of_Mf->m_five_thirds,powers_of_Mf->m_four_thirds,powers_of_Mf->m_one,powers_of_Mf->m_two_thirds,powers_of_Mf->m_one_third,1.,powers_of_Mf->one_third,powers_of_Mf->two_thirds, Mf, powers_of_Mf->four_thirds, powers_of_Mf->five_thirds, powers_of_Mf->two,powers_of_Mf->seven_thirds};
     double logMf=powers_of_Mf->log;
     for(int i=0; i<N_MAX_COEFFICIENTS_PHASE_INS; i++)
         philm+=(pPhase->phi[i]+pPhase->phiL[i]*(logMf))*freqs[i];
@@ -748,8 +1103,8 @@ static double IMRPhenomXHM_Inspiral_Phase_Ansatz(double Mf, IMRPhenomX_UsefulPow
 {
     //compute the orbital phase by laoding the rescaled phenX coefficients
     double dphilm=0.;
-    double coeffs[]={-5./3,-4./3,-1.,-2./3,-1./3,0.,1./3, 2./3, 1., 4./3, 5./3, 2., 7./3};
-    double freqs[]={powers_of_Mf->m_eight_thirds,powers_of_Mf->m_seven_thirds,powers_of_Mf->m_two,powers_of_Mf->m_five_thirds,powers_of_Mf->m_four_thirds,powers_of_Mf->m_one,powers_of_Mf->m_two_thirds,powers_of_Mf->m_one_third,1.,powers_of_Mf->one_third, powers_of_Mf->two_thirds, Mf,powers_of_Mf->four_thirds};
+    double coeffs[N_MAX_COEFFICIENTS_PHASE_INS]={-5./3,-4./3,-1.,-2./3,-1./3,0.,1./3, 2./3, 1., 4./3, 5./3, 2., 7./3};
+    double freqs[N_MAX_COEFFICIENTS_PHASE_INS]={powers_of_Mf->m_eight_thirds,powers_of_Mf->m_seven_thirds,powers_of_Mf->m_two,powers_of_Mf->m_five_thirds,powers_of_Mf->m_four_thirds,powers_of_Mf->m_one,powers_of_Mf->m_two_thirds,powers_of_Mf->m_one_third,1.,powers_of_Mf->one_third, powers_of_Mf->two_thirds, Mf,powers_of_Mf->four_thirds};
     double logMf=powers_of_Mf->log;
 
     for(int i=0; i<N_MAX_COEFFICIENTS_PHASE_INS; i++)
diff --git a/lalsimulation/lib/LALSimIMRPhenomXHM_inspiral.h b/lalsimulation/lib/LALSimIMRPhenomXHM_inspiral.h
index 53534ebc50c6cfe65f76a4431256d24dbe8d544c..27857b5ee0bbb0a5781aeef9fb0dbb97638ffad1 100644
--- a/lalsimulation/lib/LALSimIMRPhenomXHM_inspiral.h
+++ b/lalsimulation/lib/LALSimIMRPhenomXHM_inspiral.h
@@ -37,26 +37,29 @@ extern "C" {
 #define UNUSED
 #endif
 
+
+#include "LALSimIMRPhenomX_internals.h"
 #include "LALSimIMRPhenomXUtilities.h"
 #include "LALSimIMRPhenomXHM_structs.h"
-#include "LALSimIMRPhenomX_internals.h"
 
 
 /********** AMPLITUDE ***************/
 
 //Collocations Points Fits
-static double IMRPhenomXHM_Insp_Amp_21_iv1(double eta, double S, double chi1, double chi2, int InspAmpFlag);
-static double IMRPhenomXHM_Insp_Amp_21_iv2(double eta, double S, double chi1, double chi2, int InspAmpFlag);
-static double IMRPhenomXHM_Insp_Amp_21_iv3(double eta, double S, double chi1, double chi2, int InspAmpFlag);
-static double IMRPhenomXHM_Insp_Amp_33_iv1(double eta, double S, double chi1, double chi2, int InspAmpFlag);
-static double IMRPhenomXHM_Insp_Amp_33_iv2(double eta, double S, double chi1, double chi2, int InspAmpFlag);
-static double IMRPhenomXHM_Insp_Amp_33_iv3(double eta, double S, double chi1, double chi2, int InspAmpFlag);
-static double IMRPhenomXHM_Insp_Amp_32_iv1(double eta, double S, double chi1, double chi2, int InspAmpFlag);
-static double IMRPhenomXHM_Insp_Amp_32_iv2(double eta, double S, double chi1, double chi2, int InspAmpFlag);
-static double IMRPhenomXHM_Insp_Amp_32_iv3(double eta, double S, double chi1, double chi2, int InspAmpFlag);
-static double IMRPhenomXHM_Insp_Amp_44_iv1(double eta, double S, double chi1, double chi2, int InspAmpFlag);
-static double IMRPhenomXHM_Insp_Amp_44_iv2(double eta, double S, double chi1, double chi2, int InspAmpFlag);
-static double IMRPhenomXHM_Insp_Amp_44_iv3(double eta, double S, double chi1, double chi2, int InspAmpFlag);
+static double IMRPhenomXHM_Insp_Amp_21_iv1(IMRPhenomXWaveformStruct *pWF, int InspAmpFlag);
+static double IMRPhenomXHM_Insp_Amp_21_iv2(IMRPhenomXWaveformStruct *pWF, int InspAmpFlag);
+static double IMRPhenomXHM_Insp_Amp_21_iv3(IMRPhenomXWaveformStruct *pWF, int InspAmpFlag);
+static double IMRPhenomXHM_Insp_Amp_33_iv1(IMRPhenomXWaveformStruct *pWF, int InspAmpFlag);
+static double IMRPhenomXHM_Insp_Amp_33_iv2(IMRPhenomXWaveformStruct *pWF, int InspAmpFlag);
+static double IMRPhenomXHM_Insp_Amp_33_iv3(IMRPhenomXWaveformStruct *pWF, int InspAmpFlag);
+static double IMRPhenomXHM_Insp_Amp_32_iv1(IMRPhenomXWaveformStruct *pWF, int InspAmpFlag);
+static double IMRPhenomXHM_Insp_Amp_32_iv2(IMRPhenomXWaveformStruct *pWF, int InspAmpFlag);
+static double IMRPhenomXHM_Insp_Amp_32_iv3(IMRPhenomXWaveformStruct *pWF, int InspAmpFlag);
+static double IMRPhenomXHM_Insp_Amp_44_iv1(IMRPhenomXWaveformStruct *pWF, int InspAmpFlag);
+static double IMRPhenomXHM_Insp_Amp_44_iv2(IMRPhenomXWaveformStruct *pWF, int InspAmpFlag);
+static double IMRPhenomXHM_Insp_Amp_44_iv3(IMRPhenomXWaveformStruct *pWF, int InspAmpFlag);
+
+/* End of Parameter Space Fits */
 
 /******************* Pseudo PN Amplitude coefficients ***************************/
 static double IMRPhenomXHM_Inspiral_Amp_rho1(double v1, double v2, double v3, IMRPhenomX_UsefulPowers *powers_of_fcut3, IMRPhenomX_UsefulPowers *powers_of_f1, IMRPhenomX_UsefulPowers *powers_of_f2, IMRPhenomX_UsefulPowers *powers_of_f3, IMRPhenomXHMWaveformStruct *pWFHM);
@@ -80,14 +83,17 @@ void IMRPhenomXHM_Inspiral_Amplitude_Veto(
 );
 static int WavyPoints(double p1, double p2, double p3);
 
+void IMRPhenomXHM_Get_Inspiral_Amp_Coefficients(IMRPhenomXHMAmpCoefficients *pAmp, IMRPhenomXHMWaveformStruct *pWFHM, IMRPhenomXWaveformStruct *pWF22);
+static void IMRPhenomXHM_Inspiral_Amp_CollocationPoints(IMRPhenomXHMAmpCoefficients *pAmp, IMRPhenomXHMWaveformStruct *pWFHM, IMRPhenomXWaveformStruct *pWF22);
+static void IMRPhenomXHM_Inspiral_Amp_Coefficients(IMRPhenomXHMAmpCoefficients *pAmp, IMRPhenomX_UsefulPowers* powers_of_Mf_inspcollpoints, IMRPhenomXHMWaveformStruct *pWFHM);
 
 /*********** PHASE ***************/
 
 //Fits across parameter space
-static double IMRPhenomXHM_Insp_Phase_21_lambda(double eta, double S, double chi1, double chi2, int InspPhaseFlag);
-static double IMRPhenomXHM_Insp_Phase_32_lambda(double eta, double S, double chi1, double chi2, int InspPhaseFlag);
-static double IMRPhenomXHM_Insp_Phase_33_lambda(double eta, double S, double chi1, double chi2, int InspPhaseFlag);
-static double IMRPhenomXHM_Insp_Phase_44_lambda(double eta, double S, double chi1, double chi2, int InspPhaseFlag);
+static double IMRPhenomXHM_Insp_Phase_21_lambda(IMRPhenomXWaveformStruct *pWF, int InspPhaseFlag);
+static double IMRPhenomXHM_Insp_Phase_32_lambda(IMRPhenomXWaveformStruct *pWF, int InspPhaseFlag);
+static double IMRPhenomXHM_Insp_Phase_33_lambda(IMRPhenomXWaveformStruct *pWF, int InspPhaseFlag);
+static double IMRPhenomXHM_Insp_Phase_44_lambda(IMRPhenomXWaveformStruct *pWF, int InspPhaseFlag);
 static double IMRPhenomXHM_Insp_Phase_LambdaPN(double eta, int modeInt);
 
 //Ansatzs
diff --git a/lalsimulation/lib/LALSimIMRPhenomXHM_intermediate.c b/lalsimulation/lib/LALSimIMRPhenomXHM_intermediate.c
index 2066688d6ea3e66f19988442f54e78e8c7de1626..c7c5693bd8350dab1fe25ad5a320fd0bc62136dc 100644
--- a/lalsimulation/lib/LALSimIMRPhenomXHM_intermediate.c
+++ b/lalsimulation/lib/LALSimIMRPhenomXHM_intermediate.c
@@ -44,167 +44,303 @@
 
 // The dominant spin parameter is S = (m1^2*chi1 + m2^2*chi2)/(m1^2 + m2^2)
 
+/* Start of Amp Parameter Space Fits */
 
-static double IMRPhenomXHM_Inter_Amp_21_int1(double eta, double S, double chi1, double chi2, int InterAmpFlag) {
-  UNUSED double total=0,eta2,eta3,eta4,S2,S3;
+static double IMRPhenomXHM_Inter_Amp_21_int1(IMRPhenomXWaveformStruct *pWF, int InterAmpFlag) {
+  double total=0;
   switch (InterAmpFlag){
     case 122018:{
+      double eta = pWF->eta;
+      double S = pWF->STotR;
+      double eta2,S2;
       eta2 = pow(eta,2);
-      eta3 = pow(eta,3);
-      eta4 = pow(eta,4);
       S2 = pow(S,2);
-      S3 = pow(S,3);
       double noSpin = sqrt(eta - 4.*eta2)*(21.256776327599113 - 25.594352690383847*eta + 30.14761650482866*eta2);
       double eqSpin = sqrt(eta - 4.*eta2)*S*(-11.262044985632757 - 1.8167045597937677*S + eta*(-1.1798437990445079 + 6.344825546437461*S - 4.881427482271166*S2));
-      double uneqSpin = -3.6366100759176696*pow(chi1 - 1.*chi2,2)*(1. - 4.*eta)*eta - 31.60048733143782*(chi1 - 1.*chi2)*eta2*(1. + 2.1502870640831855*eta2);
+      double uneqSpin = -3.6366100759176696*pow(pWF->dchi,2)*(1. - 4.*eta)*eta - 31.60048733143782*(pWF->dchi)*eta2*(1. + 2.1502870640831855*eta2);
       total = noSpin + eqSpin + uneqSpin;
       break;
     }
-    default:{XLAL_ERROR_REAL8(XLAL_EINVAL,"Error in IMRPhenomXHM_Inter_Amp_21_int1: version is not valid. Recommended version is 122018.");}
+        case 122022:{
+            double eta = pWF->eta;
+            double delta = pWF->delta;
+            double S = pWF->STotR;
+            double chidiff = pWF->dchi_half;
+            double eta1 = eta;
+            double eta2 = eta1 * eta1;
+            double eta3 = eta1 * eta2;
+            double eta4 = eta1 * eta3;
+            double eta5 = eta1 * eta4;
+            double S1 = S;
+            double S2 = S1 * S1;
+            double chidiff1 = chidiff;
+            double chidiff2 = chidiff1 * chidiff1;
+            total = fabs(delta*eta1*(chidiff2*(5.159755997682368*eta1 - 30.293198248154948*eta2 + 63.70715919820867*eta3) + chidiff1*(8.262642080222694*eta1 - 415.88826990259116*eta2 + 1427.5951158851076*eta3)) + delta*eta1*(18.55363583212328 - 66.46950491124205*eta1 + 447.2214642597892*eta2 - 1614.178472020212*eta3 + 2199.614895727586*eta4) + chidiff1*eta5*(-1698.841763891122 - 195.27885562092342*S1 - 1.3098861736238572*S2) + delta*eta1*(chidiff1*(34.17829404207186*eta1 - 386.34587928670015*eta2 + 1022.8553774274128*eta3)*S1 + chidiff1*(56.76554600963724*eta1 - 491.4593694689354*eta2 + 1016.6019654342113*eta3)*S2) + delta*eta1*S1*(-8.276366844994188*(1.0677538075697492 - 24.12941323757896*eta1 + 516.7886322104276*eta2 - 4389.799658723288*eta3 + 16770.447637953577*eta4 - 23896.392706809565*eta5) - 1.6908277400304084*(3.4799140066657928 - 29.00026389706585*eta1 + 114.8330693231833*eta2 - 184.13091281984674*eta3 + 592.300353344717*eta4 - 2085.0821513466053*eta5)*S1 - 0.46006975902558517*(-2.1663474937625975 + 826.026625945615*eta1 - 17333.549622759732*eta2 + 142904.08962903373*eta3 - 528521.6231015554*eta4 + 731179.456702448*eta5)*S2));
+            break;
+        }
+        default:{XLAL_ERROR_REAL8(XLAL_EINVAL,"Error in IMRPhenomXHM_Inter_Amp_21_int1: version %i is not valid.", InterAmpFlag);}
   }
   return total;
 }
 
-static double IMRPhenomXHM_Inter_Amp_21_int2(double eta, double S, double chi1, double chi2, int InterAmpFlag) {
-  UNUSED double total=0, eta2,eta3,eta4,S2;
+static double IMRPhenomXHM_Inter_Amp_21_int2(IMRPhenomXWaveformStruct *pWF, int InterAmpFlag) {
+  double total=0;
   switch (InterAmpFlag){
     case 122018:{
-      eta2 = pow(eta,2);
-      eta3 = pow(eta,3);
-      eta4 = pow(eta,4);
-      S2 = pow(S,2);
+      double eta = pWF->eta;
+      double S = pWF->STotR;
+      double eta2 = pow(eta,2);
       double noSpin = sqrt(eta - 4.*eta2)*(19.15445065708005 - 21.13596229438309*eta + 29.742565944285772*eta2);
       double eqSpin = sqrt(eta - 4.*eta2)*S*(-12.766814596085734 - 2.123816950673979*S + eta*(-2.913184982025043 + 6.006571549661901*S));
-      double uneqSpin = -25.856046423804255*(chi1 - 1.*chi2)*eta2*(1. + 5.7871199275552*eta2);
+      double uneqSpin = -25.856046423804255*(pWF->dchi)*eta2*(1. + 5.7871199275552*eta2);
       total = noSpin + eqSpin + uneqSpin;
       break;
     }
-    default:{XLAL_ERROR_REAL8(XLAL_EINVAL,"Error in IMRPhenomXHM_Inter_Amp_21_int2: version is not valid. Recommended version is 122018.");}
+        case 122022:{
+            double eta = pWF->eta;
+            double delta = pWF->delta;
+            double S = pWF->STotR;
+            double chidiff = pWF->dchi_half;
+            double eta1 = eta;
+            double eta2 = eta1 * eta1;
+            double eta3 = eta1 * eta2;
+            double eta4 = eta1 * eta3;
+            double eta5 = eta1 * eta4;
+            double S1 = S;
+            double S2 = S1 * S1;
+            double chidiff1 = chidiff;
+            total = fabs(delta*eta1*(13.757856231617446 - 12.783698329428516*eta1 + 12.048194546899204*eta2) + chidiff1*delta*eta1*(15.107530092096438*eta1 - 416.811753638553*eta2 + 1333.6181181686939*eta3) + chidiff1*eta5*(-1549.6199518612063 - 102.34716990474509*S1 - 3.3637011939285015*S2) + delta*eta1*(chidiff1*(36.358142200869295*eta1 - 384.2123173145321*eta2 + 984.6826660818275*eta3)*S1 + chidiff1*(4.159271594881928*eta1 + 105.10911749116399*eta2 - 639.190132707115*eta3)*S2) + delta*eta1*S1*(-8.097876227116853*(0.6569459700232806 + 9.861355377849485*eta1 - 116.88834714736281*eta2 + 593.8035334117192*eta3 - 1063.0692862578455*eta4) - 1.0546375154878165*(0.745557030602097 + 65.25215540635162*eta1 - 902.5751736558435*eta2 + 4350.442990924205*eta3 - 7141.611333893155*eta4)*S1 - 0.5006664599166409*(10.289020582277626 - 212.00728173197498*eta1 + 2334.0029399672358*eta2 - 11939.621138801092*eta3 + 21974.8201355744*eta4)*S2));
+            break;
+        }
+        default:{XLAL_ERROR_REAL8(XLAL_EINVAL,"Error in IMRPhenomXHM_Inter_Amp_21_int2: version %i is not valid.", InterAmpFlag);}
   }
   return total;
 }
 
-static double IMRPhenomXHM_Inter_Amp_33_int1(double eta, double S, double chi1, double chi2, int InterAmpFlag) {
-  UNUSED double total=0, eta2,eta3,eta4,eta5,eta6,S2;
+static double IMRPhenomXHM_Inter_Amp_33_int1(IMRPhenomXWaveformStruct *pWF, int InterAmpFlag) {
+  double total=0;
   switch (InterAmpFlag){
     case 122018:{
+      double eta = pWF->eta;
+      double S = pWF->STotR;
+      double eta2,eta3,eta4,eta6;
       eta2 = pow(eta,2);
       eta3 = pow(eta,3);
       eta4 = pow(eta,4);
-      eta5 = pow(eta,5);
       eta6 = pow(eta,6);
-      S2 = pow(S,2);
       double noSpin = sqrt(eta - 4.*eta2)*(27.927652424857733 - 133.56611389260297*eta + 974.8550901501316*eta2 - 3744.785831952632*eta3 + 5621.897260910284*eta4);
       double eqSpin = sqrt(eta - 4.*eta2)*S*(7.348313807306079 + eta*(-60.248696675045565 - 37.07212326362276*S) + 5.059236579431119*S + eta2*(159.68630712802727 + 83.33807316873204*S));
-      double uneqSpin = 1412.367880056888*(chi1 - 1.*chi2)*eta6;
+      double uneqSpin = 1412.367880056888*(pWF->dchi)*eta6;
       total = noSpin + eqSpin + uneqSpin;
       break;
     }
-    default:{XLAL_ERROR_REAL8(XLAL_EINVAL,"Error in IMRPhenomXHM_Inter_Amp_33_int1: version is not valid. Recommended version is 122018.");}
+        case 122022:{
+            double eta = pWF->eta;
+            double delta = pWF->delta;
+            double S = pWF->STotR;
+            double chidiff = pWF->dchi_half;
+            double eta1 = eta;
+            double eta2 = eta1 * eta1;
+            double eta3 = eta1 * eta2;
+            double eta4 = eta1 * eta3;
+            double eta5 = eta1 * eta4;
+            double S1 = S;
+            double S2 = S1 * S1;
+            double chidiff1 = chidiff;
+            total = chidiff1*delta*eta1*(-0.3516244197696068*eta1 + 40.425151307421416*eta2 - 148.3162618111991*eta3) + delta*eta1*(26.998512565991778 - 146.29035440932105*eta1 + 914.5350366065115*eta2 - 3047.513201789169*eta3 + 3996.417635728702*eta4) + chidiff1*delta*eta1*(5.575274516197629*eta1 - 44.592719238427094*eta2 + 99.91399033058927*eta3)*S1 + delta*eta1*S1*(-0.5383304368673182*(-7.456619067234563 + 129.36947401891433*eta1 - 843.7897535238325*eta2 + 3507.3655567272644*eta3 - 9675.194644814854*eta4 + 11959.83533107835*eta5) - 0.28042799223829407*(-6.212827413930676 + 266.69059813274475*eta1 - 4241.537539226717*eta2 + 32634.43965039936*eta3 - 119209.70783201039*eta4 + 166056.27237509796*eta5)*S1) + chidiff1*eta5*(199.6863414922219 + 53.36849263931051*S1 + 7.650565415855383*S2);
+            break;
+        }
+        default:{XLAL_ERROR_REAL8(XLAL_EINVAL,"Error in IMRPhenomXHM_Inter_Amp_33_int1: version %i is not valid.", InterAmpFlag);}
   }
   return total;
 }
 
-static double IMRPhenomXHM_Inter_Amp_33_int2(double eta, double S, double chi1, double chi2, int InterAmpFlag) {
-  UNUSED double total=0, eta2,eta3,eta4,eta5,eta6,S2;
+static double IMRPhenomXHM_Inter_Amp_33_int2(IMRPhenomXWaveformStruct *pWF, int InterAmpFlag) {
+  double total=0;
   switch (InterAmpFlag){
     case 122018:{
+      double eta = pWF->eta;
+      double S = pWF->STotR;
+      double eta2,eta6;
       eta2 = pow(eta,2);
-      eta3 = pow(eta,3);
-      eta4 = pow(eta,4);
-      eta5 = pow(eta,5);
       eta6 = pow(eta,6);
-      S2 = pow(S,2);
       double noSpin = sqrt(eta - 4.*eta2)*(20.162169689041903 - 18.666422946967764*eta + 53.04107631052987*eta2);
       double eqSpin = sqrt(eta - 4.*eta2)*S*(3.896260108714186 + eta*(-33.707998325000965 - 61.1244771077077*S) + 4.878506403725656*S + eta2*(91.31681057861915 + 196.40535070402336*S));
-      double uneqSpin = 1637.4256048973248*(chi1 - 1.*chi2)*eta6;
+      double uneqSpin = 1637.4256048973248*(pWF->dchi)*eta6;
       total = noSpin + eqSpin + uneqSpin;
       break;
     }
-    default:{XLAL_ERROR_REAL8(XLAL_EINVAL,"Error in IMRPhenomXHM_Inter_Amp_33_int2: version is not valid. Recommended version is 122018.");}
+        case 122022:{
+            double eta = pWF->eta;
+            double delta = pWF->delta;
+            double S = pWF->STotR;
+            double chidiff = pWF->dchi_half;
+            double eta1 = eta;
+            double eta2 = eta1 * eta1;
+            double eta3 = eta1 * eta2;
+            double eta4 = eta1 * eta3;
+            double eta5 = eta1 * eta4;
+            double S1 = S;
+            double S2 = S1 * S1;
+            double chidiff1 = chidiff;
+            total = delta*eta1*(17.42562079069636 - 28.970875603981295*eta1 + 50.726220750178435*eta2) + chidiff1*delta*eta1*(-7.861956897615623*eta1 + 93.45476935080045*eta2 - 273.1170921735085*eta3) + chidiff1*delta*eta1*(-0.3265505633310564*eta1 - 9.861644053348053*eta2 + 60.38649425562178*eta3)*S1 + chidiff1*eta5*(234.13476431269862 + 51.2153901931183*S1 - 10.05114600643587*S2) + delta*eta1*S1*(0.3104472390387834*(6.073591341439855 + 169.85423386969634*eta1 - 4964.199967099143*eta2 + 42566.59565666228*eta3 - 154255.3408672655*eta4 + 205525.13910847943*eta5) + 0.2295327944679772*(19.236275867648594 - 354.7914372697625*eta1 + 1876.408148917458*eta2 + 2404.4151687877525*eta3 - 41567.07396803811*eta4 + 79210.33893514868*eta5)*S1 + 0.30983324991828787*(11.302200127272357 - 719.9854052004307*eta1 + 13278.047199998868*eta2 - 104863.50453518033*eta3 + 376409.2335857397*eta4 - 504089.07690692553*eta5)*S2);
+            break;
+        }
+        default:{XLAL_ERROR_REAL8(XLAL_EINVAL,"Error in IMRPhenomXHM_Inter_Amp_33_int2: version %i is not valid.", InterAmpFlag);}
   }
   return total;
 }
 
-static double IMRPhenomXHM_Inter_Amp_32_int1(double eta, double S, double chi1, double chi2, int InterAmpFlag) {
-  UNUSED double total=0, delta=sqrt(1. - 4.*eta),eta2,eta3,eta4,eta5,eta6,eta7,S2;
+static double IMRPhenomXHM_Inter_Amp_32_int1(IMRPhenomXWaveformStruct *pWF, int InterAmpFlag) {
+  double total=0;
   switch (InterAmpFlag){
     case 122018:{
+      double eta = pWF->eta;
+      double S = pWF->STotR;
+      double delta=sqrt(1.-4*eta),eta2,eta3,eta4,eta5,eta6;
       eta2 = pow(eta,2);
       eta3 = pow(eta,3);
       eta4 = pow(eta,4);
       eta5 = pow(eta,5);
       eta6 = pow(eta,6);
-      eta7 = pow(eta,7);
-      S2 = pow(S,2);
       double noSpin = sqrt(eta - 3.*eta2)*(6.523612598187996 - 56.93956111746338*eta + 1021.6414686597869*eta2 - 12107.114370361525*eta3 + 76320.90587515048*eta4 - 244144.92645448362*eta5 + 321790.55131499085*eta6);
       double eqSpin = sqrt(eta - 3.*eta2)*S*(2.9649243713119895 + eta3*(1790.8363334078751 - 5438.911035114849*S) + eta*(-37.87005271181108 - 126.1263286618178*S) + 4.063724538613828*S + eta2*(48.39743086535961 + 1341.2619677741804*S) + eta4*(-5200.659417644607 + 7369.386205324284*S));
-      double uneqSpin = eta2*(-0.4386152975075188*(pow(chi1,2) - 2.*chi1*chi2 + pow(chi2,2)) + (chi2*(3.6527252109313233 - 7.324266404418883*S) + chi1*(-3.6527252109313233 + 7.324266404418883*S))*delta);
+      double uneqSpin = eta2*(-0.4386152975075188*(pow(pWF->chi1L,2) - 2.*pWF->chi1L*pWF->chi2L + pow(pWF->chi2L,2)) + (pWF->chi2L*(3.6527252109313233 - 7.324266404418883*S) + pWF->chi1L*(-3.6527252109313233 + 7.324266404418883*S))*delta);
       total = noSpin + eqSpin + uneqSpin;
       break;
     }
-    default:{XLAL_ERROR_REAL8(XLAL_EINVAL,"Error in IMRPhenomXHM_Inter_Amp_32_int1: version is not valid. Recommended version is 122018.");}
+        case 122022:{
+            double eta = pWF->eta;
+            double delta = pWF->delta;
+            double sqroot = sqrt(eta);
+            double S = pWF->chiPNHat;
+            double chidiff = pWF->dchi_half;
+            double eta1 = eta;
+            double eta2 = eta1 * eta1;
+            double eta3 = eta1 * eta2;
+            double eta4 = eta1 * eta3;
+            double eta5 = eta1 * eta4;
+            double S1 = S;
+            double chidiff1 = chidiff;
+            double chidiff2 = chidiff1 * chidiff1;
+            total = (chidiff2*(-0.2341404256829785*eta1 + 2.606326837996192*eta2 - 8.68296921440857*eta3) + chidiff1*delta*(0.5454562486736877*eta1 - 25.19759222940851*eta2 + 73.40268975811729*eta3))*sqroot + chidiff1*delta*(0.4422257616009941*eta1 - 8.490112284851655*eta2 + 32.22238925527844*eta3)*S1*sqroot + S1*(0.7067243321652764*(0.12885110296881636 + 9.608999847549535*eta1 - 85.46581740280585*eta2 + 325.71940024255775*eta3 + 175.4194342269804*eta4 - 1929.9084724384807*eta5) + 0.1540566313813899*(-0.3261041495083288 + 45.55785402900492*eta1 - 827.591235943271*eta2 + 7184.647314370326*eta3 - 28804.241518798244*eta4 + 43309.69769878964*eta5)*S1)*sqroot + (480.0434256230109*eta1 + 25346.341240810478*eta2 - 99873.4707358776*eta3 + 106683.98302194536*eta4)*sqroot*pow(1 + 1082.6574834474493*eta1 + 10083.297670051445*eta2,-1);
+            break;
+        }
+        default:{XLAL_ERROR_REAL8(XLAL_EINVAL,"Error in IMRPhenomXHM_Inter_Amp_32_int1: version %i is not valid.", InterAmpFlag);}
   }
   return total;
 }
 
-static double IMRPhenomXHM_Inter_Amp_32_int2(double eta, double S, double chi1, double chi2, int InterAmpFlag) {
-  UNUSED double total=0, delta=sqrt(1. - 4.*eta),eta2,eta3,eta4,eta5,S2,S3;
+static double IMRPhenomXHM_Inter_Amp_32_int2(IMRPhenomXWaveformStruct *pWF, int InterAmpFlag) {
+  double total=0;
   switch (InterAmpFlag){
     case 122018:{
+      double eta = pWF->eta;
+      double S = pWF->STotR;
+      double delta=sqrt(1.-4.*eta),eta2,eta3,eta4,S2;
       eta2 = pow(eta,2);
       eta3 = pow(eta,3);
       eta4 = pow(eta,4);
-      eta5 = pow(eta,5);
       S2 = pow(S,2);
-      S3 = pow(S,3);
       double noSpin = sqrt(eta - 3.*eta2)*(5.941845842405418 - 31.905244419036794*eta + 271.105632998832*eta2 - 2113.9652334868965*eta3 + 6214.038393898584*eta4);
       double eqSpin = sqrt(eta - 3.*eta2)*S*(-2.726472456645038 + 2.9454485454761827*S + eta3*(10581.664858726683 - 8474.190197512324*S - 11680.937129551317*S2) + eta*(98.08119212251981 - 119.88112323140916*S - 145.5079981415436*S2) + 3.5684571473795095*S2 + eta2*(-1595.8027347570667 + 1686.7137359336039*S + 2139.8290160628144*S2) + eta4*(-21488.25117198268 + 13866.428366595079*S + 20863.270079587106*S2));
-      double uneqSpin = 0.0038732029045487884*(chi1 - 1.*chi2)*eta2*delta;
+      double uneqSpin = 0.0038732029045487884*(pWF->dchi)*eta2*delta;
       total = noSpin + eqSpin + uneqSpin;
       break;
     }
-    default:{XLAL_ERROR_REAL8(XLAL_EINVAL,"Error in IMRPhenomXHM_Inter_Amp_32_int2: version is not valid. Recommended version is 122018.");}
+        case 122022:{
+            double eta = pWF->eta;
+            double delta = pWF->delta;
+            double S = pWF->STotR;
+            double chidiff = pWF->dchi_half;
+            double eta1 = eta;
+            double eta2 = eta1 * eta1;
+            double eta3 = eta1 * eta2;
+            double eta4 = eta1 * eta3;
+            double eta5 = eta1 * eta4;
+            double eta6 = eta1 * eta5;
+            double S1 = S;
+            double chidiff1 = chidiff;
+            double chidiff2 = chidiff1 * chidiff1;
+            total = eta1*(chidiff2*(-4.175680729484314*eta1 + 47.54281549129226*eta2 - 128.88334273588077*eta3) + chidiff1*delta*(-0.18274358639599947*eta1 - 71.01128541687838*eta2 + 208.07105580635888*eta3)) + eta1*(4.760999387359598 - 38.57900689641654*eta1 + 456.2188780552874*eta2 - 4544.076411013166*eta3 + 24956.9592553473*eta4 - 69430.10468748478*eta5 + 77839.74180254337*eta6) + chidiff1*delta*eta1*(1.2198776533959694*eta1 - 26.816651899746475*eta2 + 68.72798751937934*eta3)*S1 + eta1*S1*(1.5098291294292217*(0.4844667556328104 + 9.848766999273414*eta1 - 143.66427232396376*eta2 + 856.9917885742416*eta3 - 1633.3295758142904*eta4) + 0.32413108737204144*(2.835358206961064 - 62.37317183581803*eta1 + 761.6103793011912*eta2 - 3811.5047139343505*eta3 + 6660.304740652403*eta4)*S1);
+            break;
+        }
+        default:{XLAL_ERROR_REAL8(XLAL_EINVAL,"Error in IMRPhenomXHM_Inter_Amp_32_int2: version %i is not valid.", InterAmpFlag);}
   }
   return total;
 }
 
-static double IMRPhenomXHM_Inter_Amp_44_int1(double eta, double S, double chi1, double chi2, int InterAmpFlag) {
-  UNUSED double total=0, delta=sqrt(1. - 4.*eta),eta2,eta3,eta4,eta5,S2;
+static double IMRPhenomXHM_Inter_Amp_44_int1(IMRPhenomXWaveformStruct *pWF, int InterAmpFlag) {
+  double total=0;
   switch (InterAmpFlag){
     case 122018:{
+      double eta = pWF->eta;
+      double S = pWF->STotR;
+      double delta=sqrt(1.-4.*eta),eta2,eta3,eta4;
       eta2 = pow(eta,2);
       eta3 = pow(eta,3);
       eta4 = pow(eta,4);
-      eta5 = pow(eta,5);
-      S2 = pow(S,2);
       double noSpin = sqrt(eta - 3.*eta2)*(10.804555518381166 - 72.3834734399584*eta + 540.0541240482852*eta2 - 2612.999845214264*eta3 + 4779.096001663427*eta4);
       double eqSpin = sqrt(eta - 3.*eta2)*S*(4.26336253142121 + eta*(-47.94914754514519 - 39.31284390368824*S) + 3.0973959822174297*S + eta2*(119.70401520575753 + 106.91295627237112*S));
-      double uneqSpin = 0.7262636326998003*pow(chi1 - 1.*chi2,2)*(1. - 4.*eta)*eta + 3.001401833124412*(chi1 - 1.*chi2)*eta2*delta;
+      double uneqSpin = 0.7262636326998003*pow(pWF->dchi,2)*(1. - 4.*eta)*eta + 3.001401833124412*(pWF->dchi)*eta2*delta;
       total = noSpin + eqSpin + uneqSpin;
       break;
     }
-    default:{XLAL_ERROR_REAL8(XLAL_EINVAL,"Error in IMRPhenomXHM_Inter_Amp_44_int1: version is not valid. Recommended version is 122018.");}
+        case 122022:{
+            double eta = pWF->eta;
+            double delta = pWF->delta;
+            double S = pWF->chiPNHat;
+            double chidiff = pWF->dchi_half;
+            double eta1 = eta;
+            double eta2 = eta1 * eta1;
+            double eta3 = eta1 * eta2;
+            double eta4 = eta1 * eta3;
+            double S1 = S;
+            double S2 = S1 * S1;
+            double chidiff1 = chidiff;
+            double chidiff2 = chidiff1 * chidiff1;
+            total = eta1*(chidiff1*delta*(1.5378890240544967*eta1 - 3.4499418893734903*eta2 + 16.879953490422782*eta3) + chidiff2*(1.720226708214248*eta1 - 11.87925165364241*eta2 + 23.259283336239545*eta3)) + eta1*(8.790173464969538 - 64.95499142822892*eta1 + 324.1998823562892*eta2 - 1111.9864921907126*eta3 + 1575.602443847111*eta4) + eta1*S1*(-0.062333275821238224*(-21.630297087123807 + 137.4395894877131*eta1 + 64.92115530780129*eta2 - 1013.1110639471394*eta3) - 0.11014697070998722*(4.149721483857751 - 108.6912882442823*eta1 + 831.6073263887092*eta2 - 1828.2527520190122*eta3)*S1 - 0.07704777584463054*(4.581767671445529 - 50.35070009227704*eta1 + 344.9177692251726*eta2 - 858.9168637051405*eta3)*S2);
+            break;
+        }
+        default:{XLAL_ERROR_REAL8(XLAL_EINVAL,"Error in IMRPhenomXHM_Inter_Amp_44_int1: version %i is not valid.", InterAmpFlag);}
   }
   return total;
 }
 
-static double IMRPhenomXHM_Inter_Amp_44_int2(double eta, double S, double chi1, double chi2, int InterAmpFlag) {
-  UNUSED double total=0, delta=sqrt(1. - 4.*eta),eta2,eta3,eta4,eta5,S2;
+static double IMRPhenomXHM_Inter_Amp_44_int2(IMRPhenomXWaveformStruct *pWF, int InterAmpFlag) {
+  double total=0;
   switch (InterAmpFlag){
     case 122018:{
+      double eta = pWF->eta;
+      double S = pWF->STotR;
+      double delta=sqrt(1.-4.*eta),eta2,eta3,eta4;
       eta2 = pow(eta,2);
       eta3 = pow(eta,3);
       eta4 = pow(eta,4);
-      eta5 = pow(eta,5);
-      S2 = pow(S,2);
       double noSpin = sqrt(eta - 3.*eta2)*(9.020721305469884 - 53.221883492311235*eta + 508.07176447172264*eta2 - 3194.0620894511508*eta3 + 6769.9274392345915*eta4);
       double eqSpin = sqrt(eta - 3.*eta2)*S*(3.256591670091969 + eta*(-38.38922554651356 - 25.286684856422735*S) + 2.374434219852751*S + eta2*(96.41777041220982 + 64.74544118094362*S));
-      double uneqSpin = 3.2337593375595417*(chi1 - 1.*chi2)*eta2*delta;
+      double uneqSpin = 3.2337593375595417*(pWF->dchi)*eta2*delta;
       total = noSpin + eqSpin + uneqSpin;
       break;
     }
-    default:{XLAL_ERROR_REAL8(XLAL_EINVAL,"Error in IMRPhenomXHM_Inter_Amp_44_int2: version is not valid. Recommended version is 122018.");}
+            case 122022:{
+            double eta = pWF->eta;
+            double delta = pWF->delta;
+            double S = pWF->chiPNHat;
+            double chidiff = pWF->dchi_half;
+            double eta1 = eta;
+            double eta2 = eta1 * eta1;
+            double eta3 = eta1 * eta2;
+            double eta4 = eta1 * eta3;
+            double eta5 = eta1 * eta4;
+            double eta6 = eta1 * eta5;
+            double S1 = S;
+            double chidiff1 = chidiff;
+            double chidiff2 = chidiff1 * chidiff1;
+            total = eta1*(chidiff1*delta*(2.3123974306694057*eta1 - 12.237594841284904*eta2 + 44.78225529547671*eta3) + chidiff2*(2.9282931698944292*eta1 - 25.624210264341933*eta2 + 61.05270871360041*eta3)) + eta1*(6.98072197826729 - 46.81443520117986*eta1 + 236.76146303619544*eta2 - 920.358408667518*eta3 + 1478.050456337336*eta4) + eta1*S1*(-0.07801583359561987*(-28.29972282146242 + 752.1603553640072*eta1 - 10671.072606753183*eta2 + 83447.0461509547*eta3 - 350025.2112501252*eta4 + 760889.6919776166*eta5 - 702172.2934567826*eta6) + 0.013159545629626014*(91.1469833190294 - 3557.5003799977294*eta1 + 52391.684517955284*eta2 - 344254.9973814295*eta3 + 1.0141877915334814e6*eta4 - 1.1505186449682908e6*eta5 + 268756.85659532435*eta6)*S1);
+            break;
+        }
+        default:{XLAL_ERROR_REAL8(XLAL_EINVAL,"Error in IMRPhenomXHM_Inter_Amp_44_int2: version %i is not valid.", InterAmpFlag);}
   }
   return total;
 }
@@ -212,82 +348,93 @@ static double IMRPhenomXHM_Inter_Amp_44_int2(double eta, double S, double chi1,
 /*
 Fits for the extra collocation point for EMR cases with 2 intermediate regions
 */
-static double IMRPhenomXHM_Inter_Amp_21_int0(double eta, double S, UNUSED double chi1, UNUSED double chi2, int InterAmpFlag) {
-  UNUSED double total=0,eta2,eta3,S2;
+static double IMRPhenomXHM_Inter_Amp_21_int0(IMRPhenomXWaveformStruct *pWF, int InterAmpFlag) {
+  double total=0;
   switch (InterAmpFlag){
     case 122018:{
+      double eta = pWF->eta;
+      double S = pWF->STotR;
+      double eta2,eta3;
       eta2 = pow(eta,2);
       eta3 = pow(eta,3);
-      S2 = pow(S,2);
       double noSpin = 0.872895771366973 + 441.76285124642845*eta - 24617.068739152524*eta2 + 518054.9485981792*eta3;
       double eqSpin = S*(-0.0720494539485585 + eta*(-173.67847091983123 - 113.29725582509889*S) - 0.2687302438646897*S + eta2*(3571.0393588230045 + 2640.919925429635*S));
       double uneqSpin = 0.;
       total = noSpin + eqSpin + uneqSpin;
       break;
     }
-    default:{XLAL_ERROR_REAL8(XLAL_EINVAL,"Error in IMRPhenomXHM_Inter_Amp_21_int0: version is not valid. Recommended version is 122018.");}
+    default:{XLAL_ERROR_REAL8(XLAL_EINVAL,"Error in IMRPhenomXHM_Inter_Amp_21_int0: version is not valid.");}
   }
   return total;
 }
 
-static double IMRPhenomXHM_Inter_Amp_21_dint0(double eta, double S, UNUSED double chi1, UNUSED double chi2, int InterAmpFlag) {
-  UNUSED double total=0,eta2,eta3,S2;
+static double IMRPhenomXHM_Inter_Amp_21_dint0(IMRPhenomXWaveformStruct *pWF, int InterAmpFlag) {
+  double total=0;
   switch (InterAmpFlag){
     case 122018:{
+      double eta = pWF->eta;
+      double S = pWF->STotR;
+      double eta2,eta3;
       eta2 = pow(eta,2);
       eta3 = pow(eta,3);
-      S2 = pow(S,2);
       double noSpin = -0.8535048463050732 - 93.1876950411214*eta + 13641.071903017495*eta2 - 337621.44851304166*eta3;
       double eqSpin = S*(-1.2067842398131878 + eta2*(-1972.284151572111 - 8172.057025783849*S) - 0.26539816223182355*S + eta*(77.26350785961219 + 189.63365484152857*S));
       double uneqSpin = 0.;
       total = noSpin + eqSpin + uneqSpin;
       break;
     }
-    default:{XLAL_ERROR_REAL8(XLAL_EINVAL,"Error in IMRPhenomXHM_Inter_Amp_21_dint0: version is not valid. Recommended version is 122018.");}
+    default:{XLAL_ERROR_REAL8(XLAL_EINVAL,"Error in IMRPhenomXHM_Inter_Amp_21_dint0: version %i is not valid.", InterAmpFlag);}
   }
   return total;
 }
 
-static double IMRPhenomXHM_Inter_Amp_33_int0(double eta, double S, UNUSED double chi1, UNUSED double chi2, int InterAmpFlag) {
-  UNUSED double total=0,eta2,eta3,S2;
+static double IMRPhenomXHM_Inter_Amp_33_int0(IMRPhenomXWaveformStruct *pWF, int InterAmpFlag) {
+  double total=0;
   switch (InterAmpFlag){
     case 122018:{
+      double eta = pWF->eta;
+      double S = pWF->STotR;
+      double eta2,eta3;
       eta2 = pow(eta,2);
       eta3 = pow(eta,3);
-      S2 = pow(S,2);
       double noSpin = 1.5852399637975103 + 549.5183711492834*eta - 34257.76380246282*eta2 + 743142.8286902909*eta3;
       double eqSpin = S*(0.7436306553052219 + eta*(-89.49451655594787 - 174.5730646548662*S) + 0.4253024979725725*S + eta2*(1185.1654325913717 + 6510.983041407191*S));
       double uneqSpin = 0.;
       total = noSpin + eqSpin + uneqSpin;
       break;
     }
-    default:{XLAL_ERROR_REAL8(XLAL_EINVAL,"Error in IMRPhenomXHM_Inter_Amp_33_int0: version is not valid. Recommended version is 122018.");}
+    default:{XLAL_ERROR_REAL8(XLAL_EINVAL,"Error in IMRPhenomXHM_Inter_Amp_33_int0: version %i is not valid.", InterAmpFlag);}
   }
   return total;
 }
 
-static double IMRPhenomXHM_Inter_Amp_33_dint0(double eta, double S, UNUSED double chi1, UNUSED double chi2, int InterAmpFlag) {
-  UNUSED double total=0,eta2,eta3,S2;
+static double IMRPhenomXHM_Inter_Amp_33_dint0(IMRPhenomXWaveformStruct *pWF, int InterAmpFlag) {
+  double total=0;
   switch (InterAmpFlag){
     case 122018:{
+      double eta = pWF->eta;
+      double S = pWF->STotR;
+      double eta2,eta3;
       eta2 = pow(eta,2);
       eta3 = pow(eta,3);
-      S2 = pow(S,2);
       double noSpin = -4.691600252198376 + 101.4338937535679*eta + 9262.994550540048*eta2 - 310993.1309846956*eta3;
       double eqSpin = S*(-4.198232394219111 + eta2*(-28714.904192060643 - 5100.09336069277*S) - 0.40986595512314733*S + eta*(734.7118618746317 + 292.04566260701574*S));
       double uneqSpin = 0.;
       total = noSpin + eqSpin + uneqSpin;
       break;
     }
-    default:{XLAL_ERROR_REAL8(XLAL_EINVAL,"Error in IMRPhenomXHM_Inter_Amp_33_dint0: version is not valid. Recommended version is 122018.");}
+    default:{XLAL_ERROR_REAL8(XLAL_EINVAL,"Error in IMRPhenomXHM_Inter_Amp_33_dint0: version %i is not valid.", InterAmpFlag);}
   }
   return total;
 }
 
-static double IMRPhenomXHM_Inter_Amp_32_int0(double eta, double S, UNUSED double chi1, UNUSED double chi2, int InterAmpFlag) {
-  UNUSED double total=0,eta2,eta3,S2,S3;
+static double IMRPhenomXHM_Inter_Amp_32_int0(IMRPhenomXWaveformStruct *pWF, int InterAmpFlag) {
+  double total=0;
   switch (InterAmpFlag){
     case 122018:{
+      double eta = pWF->eta;
+      double S = pWF->STotR;
+      double eta2,eta3,S2,S3;
       eta2 = pow(eta,2);
       eta3 = pow(eta,3);
       S2 = pow(S,2);
@@ -298,33 +445,38 @@ static double IMRPhenomXHM_Inter_Amp_32_int0(double eta, double S, UNUSED double
       total = noSpin + eqSpin + uneqSpin;
       break;
     }
-    default:{XLAL_ERROR_REAL8(XLAL_EINVAL,"Error in IMRPhenomXHM_Inter_Amp_32_int0: version is not valid. Recommended version is 122018.");}
+    default:{XLAL_ERROR_REAL8(XLAL_EINVAL,"Error in IMRPhenomXHM_Inter_Amp_32_int0: version %i is not valid.", InterAmpFlag);}
   }
   return total;
 }
 
-static double IMRPhenomXHM_Inter_Amp_32_dint0(double eta, double S, UNUSED double chi1, UNUSED double chi2, int InterAmpFlag) {
-  UNUSED double total=0,eta2,eta3,S2;
+static double IMRPhenomXHM_Inter_Amp_32_dint0(IMRPhenomXWaveformStruct *pWF, int InterAmpFlag) {
+  double total=0;
   switch (InterAmpFlag){
     case 122018:{
+      double eta = pWF->eta;
+      double S = pWF->STotR;
+      double eta2,eta3;
       eta2 = pow(eta,2);
       eta3 = pow(eta,3);
-      S2 = pow(S,2);
       double noSpin = -0.3391808620221253 - 14.604141885467747*eta + 3694.1706648870427*eta2 - 95482.02951271653*eta3;
       double eqSpin = S*(-1.2844502090793946 + eta2*(-5018.762853306415 - 6332.389157828062*S) - 1.2356159239385598*S + eta*(149.04865679660233 + 188.2052849646003*S));
       double uneqSpin = 0.;
       total = noSpin + eqSpin + uneqSpin;
       break;
     }
-    default:{XLAL_ERROR_REAL8(XLAL_EINVAL,"Error in IMRPhenomXHM_Inter_Amp_32_dint0: version is not valid. Recommended version is 122018.");}
+    default:{XLAL_ERROR_REAL8(XLAL_EINVAL,"Error in IMRPhenomXHM_Inter_Amp_32_dint0: version %i is not valid.", InterAmpFlag);}
   }
   return total;
 }
 
-static double IMRPhenomXHM_Inter_Amp_44_int0(double eta, double S, UNUSED double chi1, UNUSED double chi2, int InterAmpFlag) {
-  UNUSED double total=0,eta2,eta3,S2,S3;
+static double IMRPhenomXHM_Inter_Amp_44_int0(IMRPhenomXWaveformStruct *pWF, int InterAmpFlag) {
+  double total=0;
   switch (InterAmpFlag){
     case 122018:{
+      double eta = pWF->eta;
+      double S = pWF->STotR;
+      double eta2,eta3,S2,S3;
       eta2 = pow(eta,2);
       eta3 = pow(eta,3);
       S2 = pow(S,2);
@@ -335,28 +487,227 @@ static double IMRPhenomXHM_Inter_Amp_44_int0(double eta, double S, UNUSED double
       total = noSpin + eqSpin + uneqSpin;
       break;
     }
-    default:{XLAL_ERROR_REAL8(XLAL_EINVAL,"Error in IMRPhenomXHM_Inter_Amp_44_int0: version is not valid. Recommended version is 122018.");}
+    default:{XLAL_ERROR_REAL8(XLAL_EINVAL,"Error in IMRPhenomXHM_Inter_Amp_44_int0: version %i is not valid.", InterAmpFlag);}
   }
   return total;
 }
 
-static double IMRPhenomXHM_Inter_Amp_44_dint0(double eta, double S, UNUSED double chi1, UNUSED double chi2, int InterAmpFlag) {
-  UNUSED double total=0,eta2,S2;
+static double IMRPhenomXHM_Inter_Amp_44_dint0(IMRPhenomXWaveformStruct *pWF, int InterAmpFlag) {
+  double total=0;
   switch (InterAmpFlag){
     case 122018:{
-      eta2 = pow(eta,2);
-      S2 = pow(S,2);
+      double eta = pWF->eta;
+      double S = pWF->STotR;
+      double eta2 = pow(eta,2);
       double noSpin = -1.796444922382065 + 111.51170611049032*eta - 1728.7493675776548*eta2;
       double eqSpin = S*(-1.842119860613924 + eta2*(-11235.484645624338 - 2927.019210835522*S) - 0.36655273031432567*S + eta*(312.34531117524097 + 128.64488103364167*S));
       double uneqSpin = 0.;
       total = noSpin + eqSpin + uneqSpin;
       break;
     }
-    default:{XLAL_ERROR_REAL8(XLAL_EINVAL,"Error in IMRPhenomXHM_Inter_Amp_44_dint0: version is not valid. Recommended version is 122018.");}
+    default:{XLAL_ERROR_REAL8(XLAL_EINVAL,"Error in IMRPhenomXHM_Inter_Amp_44_dint0: version %i is not valid.", InterAmpFlag);}
+  }
+  return total;
+}
+
+
+static double IMRPhenomXHM_Inter_Amp_21_int3(IMRPhenomXWaveformStruct *pWF, int InterAmpFlag){
+	double total=0;
+	switch (InterAmpFlag){
+        case 122022:{
+            double eta = pWF->eta;
+            double delta = pWF->delta;
+            double S = pWF->STotR;
+            double chidiff = pWF->dchi_half;
+            double eta1 = eta;
+            double eta2 = eta1 * eta1;
+            double eta3 = eta1 * eta2;
+            double eta4 = eta1 * eta3;
+            double eta5 = eta1 * eta4;
+            double S1 = S;
+            double S2 = S1 * S1;
+            double chidiff1 = chidiff;
+            total = fabs(delta*eta1*(13.318990196097973 - 21.755549987331054*eta1 + 76.14884211156267*eta2 - 127.62161159798488*eta3) + chidiff1*delta*eta1*(17.704321326939414*eta1 - 434.4390350012534*eta2 + 1366.2408490833282*eta3) + chidiff1*delta*eta1*(11.877985158418596*eta1 - 131.04937626836355*eta2 + 343.79587860999874*eta3)*S1 + chidiff1*eta5*(-1522.8543551416456 - 16.639896279650678*S1 + 3.0053086651515843*S2) + delta*eta1*S1*(-8.665646058245033*(0.7862132291286934 + 8.293609541933655*eta1 - 111.70764910503321*eta2 + 576.7172598056907*eta3 - 1001.2370065269745*eta4) - 0.9459820574514348*(1.309016452198605 + 48.94077040282239*eta1 - 817.7854010574645*eta2 + 4331.56002883546*eta3 - 7518.309520232795*eta4)*S1 - 0.4308267743835775*(9.970654092010587 - 302.9708323417439*eta1 + 3662.099161055873*eta2 - 17712.883990278668*eta3 + 29480.158198408903*eta4)*S2));
+            break;
+        }
+    default:{XLAL_ERROR_REAL8(XLAL_EINVAL,"Error in IMRPhenomXHM_Inter_Amp_21_int3:version %i is not valid.", InterAmpFlag);}
   }
   return total;
 }
 
+static double IMRPhenomXHM_Inter_Amp_21_int4(IMRPhenomXWaveformStruct *pWF, int InterAmpFlag){
+	double total=0;
+	switch (InterAmpFlag){
+        case 122022:{
+            double eta = pWF->eta;
+            double delta = pWF->delta;
+            double S = pWF->STotR;
+            double chidiff = pWF->dchi_half;
+            double eta1 = eta;
+            double eta2 = eta1 * eta1;
+            double eta3 = eta1 * eta2;
+            double eta4 = eta1 * eta3;
+            double eta5 = eta1 * eta4;
+            double S1 = S;
+            double S2 = S1 * S1;
+            double chidiff1 = chidiff;
+            total = fabs(delta*eta1*(13.094382343446163 - 22.831152256559523*eta1 + 83.20619262213437*eta2 - 139.25546924151664*eta3) + chidiff1*delta*eta1*(20.120192352555357*eta1 - 458.2592421214168*eta2 + 1430.3698681181*eta3) + chidiff1*delta*eta1*(12.925363020014743*eta1 - 126.87194512915104*eta2 + 280.6003655502327*eta3)*S1 + chidiff1*eta5*(-1528.956015503355 + 74.44462583487345*S1 - 2.2456928156392197*S2) + delta*eta1*S1*(-9.499741513411829*(0.912120958549489 + 2.400945118514037*eta1 - 33.651192908287236*eta2 + 166.04254881175257*eta3 - 248.5050377498615*eta4) - 0.7850652143322492*(1.534131218043425 + 60.81773903539479*eta1 - 1032.1319480683567*eta2 + 5381.481380750608*eta3 - 9077.037917192794*eta4)*S1 - 0.21540359093306097*(9.42805409480658 - 109.06544597367301*eta1 + 385.8345793110262*eta2 + 1889.9613367802453*eta3 - 9835.416414460055*eta4)*S2));
+            break;
+        }
+    default:{XLAL_ERROR_REAL8(XLAL_EINVAL,"Error in IMRPhenomXHM_Inter_Amp_21_int4:version %i is not valid.", InterAmpFlag);}
+  }
+  return total;
+}
+
+static double IMRPhenomXHM_Inter_Amp_33_int3(IMRPhenomXWaveformStruct *pWF, int InterAmpFlag){
+	double total=0;
+	switch (InterAmpFlag){
+        case 122022:{
+            double eta = pWF->eta;
+            double delta = pWF->delta;
+            double S = pWF->STotR;
+            double chidiff = pWF->dchi_half;
+            double eta1 = eta;
+            double eta2 = eta1 * eta1;
+            double eta3 = eta1 * eta2;
+            double eta4 = eta1 * eta3;
+            double eta5 = eta1 * eta4;
+            double S1 = S;
+            double S2 = S1 * S1;
+            double chidiff1 = chidiff;
+            total = delta*eta1*(14.555522136327964 - 12.799844096694798*eta1 + 16.79500349318081*eta2) + chidiff1*delta*eta1*(-16.292654447108134*eta1 + 190.3516012682791*eta2 - 562.0936797781519*eta3) + chidiff1*delta*eta1*(-7.048898856045782*eta1 + 49.941617405768135*eta2 - 73.62033985436068*eta3)*S1 + chidiff1*eta5*(263.5151703818307 + 44.408527093031566*S1 + 10.457035444964653*S2) + delta*eta1*S1*(0.4590550434774332*(3.0594364612798635 + 207.74562213604057*eta1 - 5545.0086137386525*eta2 + 50003.94075934942*eta3 - 195187.55422847517*eta4 + 282064.174913521*eta5) + 0.657748992123043*(5.57939137343977 - 124.06189543062042*eta1 + 1276.6209573025596*eta2 - 6999.7659193505915*eta3 + 19714.675715229736*eta4 - 20879.999628681435*eta5)*S1 + 0.3695850566805098*(6.077183107132255 - 498.95526910874986*eta1 + 10426.348944657859*eta2 - 91096.64982858274*eta3 + 360950.6686625352*eta4 - 534437.8832860565*eta5)*S2);
+            break;
+        }
+    default:{XLAL_ERROR_REAL8(XLAL_EINVAL,"Error in IMRPhenomXHM_Inter_Amp_33_int3:version %i is not valid.", InterAmpFlag);}
+  }
+  return total;
+}
+
+static double IMRPhenomXHM_Inter_Amp_33_int4(IMRPhenomXWaveformStruct *pWF, int InterAmpFlag){
+	double total=0;
+	switch (InterAmpFlag){
+        case 122022:{
+            double eta = pWF->eta;
+            double delta = pWF->delta;
+            double S = pWF->STotR;
+            double chidiff = pWF->dchi_half;
+            double eta1 = eta;
+            double eta2 = eta1 * eta1;
+            double eta3 = eta1 * eta2;
+            double eta4 = eta1 * eta3;
+            double eta5 = eta1 * eta4;
+            double S1 = S;
+            double S2 = S1 * S1;
+            double chidiff1 = chidiff;
+            double chidiff2 = chidiff1 * chidiff1;
+            total = delta*eta1*(13.312095699772305 - 7.449975618083432*eta1 + 17.098576301150125*eta2) + delta*eta1*(chidiff1*(-31.171150896110156*eta1 + 371.1389274783572*eta2 - 1103.1917047361735*eta3) + chidiff2*(32.78644599730888*eta1 - 395.15713118955387*eta2 + 1164.9282236341376*eta3)) + chidiff1*delta*eta1*(-46.85669289852532*eta1 + 522.3965959942979*eta2 - 1485.5134187612182*eta3)*S1 + chidiff1*eta5*(287.90444670305715 - 21.102665129433042*chidiff2 + 7.635582066682054*S1 - 29.471275170013012*S2) + delta*eta1*S1*(0.6893003654021495*(3.1014226377197027 - 44.83989278653052*eta1 + 565.3767256471909*eta2 - 4797.429130246123*eta3 + 19514.812242035154*eta4 - 27679.226582207506*eta5) + 0.7068016563068026*(4.071212304920691 - 118.51094098279343*eta1 + 1788.1730303291356*eta2 - 13485.270489656365*eta3 + 48603.96661003743*eta4 - 65658.74746265226*eta5)*S1 + 0.2181399561677432*(-1.6754158383043574 + 303.9394443302189*eta1 - 6857.936471898544*eta2 + 59288.71069769708*eta3 - 216137.90827404748*eta4 + 277256.38289831823*eta5)*S2);
+            break;
+        }
+    default:{XLAL_ERROR_REAL8(XLAL_EINVAL,"Error in IMRPhenomXHM_Inter_Amp_33_int4:version %i is not valid.", InterAmpFlag);}
+  }
+  return total;
+}
+
+static double IMRPhenomXHM_Inter_Amp_44_int3(IMRPhenomXWaveformStruct *pWF, int InterAmpFlag){
+	double total=0;
+	switch (InterAmpFlag){
+        case 122022:{
+            double eta = pWF->eta;
+            double delta = pWF->delta;
+            double S = pWF->chiPNHat;
+            double chidiff = pWF->dchi_half;
+            double eta1 = eta;
+            double eta2 = eta1 * eta1;
+            double eta3 = eta1 * eta2;
+            double eta4 = eta1 * eta3;
+            double S1 = S;
+            double S2 = S1 * S1;
+            double chidiff1 = chidiff;
+            double chidiff2 = chidiff1 * chidiff1;
+            total = eta1*(chidiff1*delta*(-0.8765502142143329*eta1 + 22.806632458441996*eta2 - 43.675503209991184*eta3) + chidiff2*(0.48698617426180074*eta1 - 4.302527065360426*eta2 + 16.18571810759235*eta3)) + eta1*(6.379772583015967 - 44.10631039734796*eta1 + 269.44092930942793*eta2 - 1285.7635006711453*eta3 + 2379.538739132234*eta4) + eta1*S1*(-0.23316184683282615*(-1.7279023138971559 - 23.606399143993716*eta1 + 409.3387618483284*eta2 - 1115.4147472977265*eta3) - 0.09653777612560172*(-5.310643306559746 - 2.1852511802701264*eta1 + 541.1248219096527*eta2 - 1815.7529908827103*eta3)*S1 - 0.060477799540741804*(-14.578189130145661 + 175.6116682068523*eta1 - 569.4799973930861*eta2 + 426.0861915646515*eta3)*S2);
+            break;
+        }
+    default:{XLAL_ERROR_REAL8(XLAL_EINVAL,"Error in IMRPhenomXHM_Inter_Amp_44_int3:version %i is not valid.", InterAmpFlag);}
+  }
+  return total;
+}
+
+static double IMRPhenomXHM_Inter_Amp_44_int4(IMRPhenomXWaveformStruct *pWF, int InterAmpFlag){
+	double total=0;
+	switch (InterAmpFlag){
+        case 122022:{
+            double eta = pWF->eta;
+            double delta = pWF->delta;
+            double S = pWF->chiPNHat;
+            double chidiff = pWF->dchi_half;
+            double eta1 = eta;
+            double eta2 = eta1 * eta1;
+            double eta3 = eta1 * eta2;
+            double eta4 = eta1 * eta3;
+            double eta5 = eta1 * eta4;
+            double S1 = S;
+            double S2 = S1 * S1;
+            double chidiff1 = chidiff;
+            double chidiff2 = chidiff1 * chidiff1;
+            total = eta1*(chidiff1*delta*(-2.461738962276138*eta1 + 45.3240543970684*eta2 - 112.2714974622516*eta3) + chidiff2*(0.9158352037567031*eta1 - 8.724582331021695*eta2 + 28.44633544874233*eta3)) + eta1*(6.098676337298138 - 45.42463610529546*eta1 + 350.97192927929433*eta2 - 2002.2013283876834*eta3 + 4067.1685640401033*eta4) + eta1*S1*(-0.36068516166901304*(-2.120354236840677 - 47.56175350408845*eta1 + 1618.4222330016048*eta2 - 14925.514654896673*eta3 + 60287.45399959349*eta4 - 91269.3745059139*eta5) - 0.09635801207669747*(-11.824692837267394 + 371.7551657959369*eta1 - 4176.398139238679*eta2 + 16655.87939259747*eta3 - 4102.218189945819*eta4 - 67024.98285179552*eta5)*S1 - 0.06565232123453196*(-26.15227471380236 + 1869.0168486099005*eta1 - 33951.35186039629*eta2 + 253694.6032002248*eta3 - 845341.6001856657*eta4 + 1.0442282862506858e6*eta5)*S2);
+            break;
+        }
+    default:{XLAL_ERROR_REAL8(XLAL_EINVAL,"Error in IMRPhenomXHM_Inter_Amp_44_int4:version %i is not valid.", InterAmpFlag);}
+  }
+  return total;
+}
+
+static double IMRPhenomXHM_Inter_Amp_32_int3(IMRPhenomXWaveformStruct *pWF, int InterAmpFlag){
+	double total=0;
+	switch (InterAmpFlag){
+        case 122022:{
+            double eta = pWF->eta;
+            double delta = pWF->delta;
+            double S = pWF->chiPNHat;
+            double chidiff = pWF->dchi_half;
+            double eta1 = eta;
+            double eta2 = eta1 * eta1;
+            double eta3 = eta1 * eta2;
+            double eta4 = eta1 * eta3;
+            double eta5 = eta1 * eta4;
+            double eta6 = eta1 * eta5;
+            double S1 = S;
+            double S2 = S1 * S1;
+            double chidiff1 = chidiff;
+            double chidiff2 = chidiff1 * chidiff1;
+            total = 3.881450518842405*eta1 - 12.580316392558837*eta2 + 1.7262466525848588*eta3 + chidiff2*(-7.065118823041031*eta2 + 77.97950589523865*eta3 - 203.65975422378446*eta4) - 58.408542930248046*eta4 + chidiff1*delta*(1.924723094787216*eta2 - 90.92716917757797*eta3 + 387.00162600306226*eta4) + 403.5748987560612*eta5 + chidiff1*delta*(-0.2566958540737833*eta2 + 14.488550203412675*eta3 - 26.46699529970884*eta4)*S1 + S1*(0.3650871458400108*(71.57390929624825*eta2 - 994.5272351916166*eta3 + 6734.058809060536*eta4 - 18580.859291282686*eta5 + 16001.318492586077*eta6) + 0.0960146077440495*(451.74917589707513*eta2 - 9719.470997418284*eta3 + 83403.5743434538*eta4 - 318877.43061174755*eta5 + 451546.88775684836*eta6)*S1 - 0.03985156529181297*(-304.92981902871617*eta2 + 3614.518459296278*eta3 - 7859.4784979916085*eta4 - 46454.57664737511*eta5 + 162398.81483375572*eta6)*S2);
+            break;
+        }
+    default:{XLAL_ERROR_REAL8(XLAL_EINVAL,"Error in IMRPhenomXHM_Inter_Amp_32_int3:version %i is not valid.", InterAmpFlag);}
+  }
+  return total;
+}
+
+static double IMRPhenomXHM_Inter_Amp_32_int4(IMRPhenomXWaveformStruct *pWF, int InterAmpFlag){
+	double total=0;
+	switch (InterAmpFlag){
+        case 122022:{
+            double eta = pWF->eta;
+            double delta = pWF->delta;
+            double S = pWF->STotR;
+            double chidiff = pWF->dchi_half;
+            double eta1 = eta;
+            double eta2 = eta1 * eta1;
+            double eta3 = eta1 * eta2;
+            double eta4 = eta1 * eta3;
+            double S1 = S;
+            double chidiff1 = chidiff;
+            double chidiff2 = chidiff1 * chidiff1;
+            total = eta1*(chidiff2*(-8.572797326909152*eta1 + 92.95723645687826*eta2 - 236.2438921965621*eta3) + chidiff1*delta*(6.674358856924571*eta1 - 171.4826985994883*eta2 + 645.2760206304703*eta3)) + eta1*(3.921660532875504 - 16.57299637423352*eta1 + 25.254017911686333*eta2 - 143.41033155133266*eta3 + 692.926425981414*eta4) + chidiff1*delta*eta1*(-3.582040878719185*eta1 + 57.75888914133383*eta2 - 144.21651114700492*eta3)*S1 + eta1*S1*(1.242750265695504*(-0.522172424518215 + 25.168480118950065*eta1 - 303.5223688400309*eta2 + 1858.1518762309654*eta3 - 3797.3561904195085*eta4) + 0.2927045241764365*(0.5056957789079993 - 15.488754837330958*eta1 + 471.64047356915603*eta2 - 3131.5783196211587*eta3 + 6097.887891566872*eta4)*S1);
+            break;
+        }
+    default:{XLAL_ERROR_REAL8(XLAL_EINVAL,"Error in IMRPhenomXHM_Inter_Amp_32_int4:version %i is not valid.", InterAmpFlag);}
+  }
+  return total;
+}
+
+/* End of Amp Parameter Space Fits */
+
 
 /* Solves system of equations for 5th order polynomial ansatz */
 
@@ -382,55 +733,55 @@ static double IMRPhenomXHM_Intermediate_Amp_delta0(double d1, double d4, double
   {
     case 101: //linear, only v1, v2
     {
-      UNUSED double f1mf4 = f1-f4;
+      double f1mf4 = f1-f4;
 
       retVal = (-(f4*v1) + f1*v4)/f1mf4;
       break;
     }
     case 102: //quadratic: v1, v2, d2
     {
-      UNUSED double f12    = f1*f1;
-      UNUSED double f42    = f4*f4;
-      UNUSED double f1mf4  = f1-f4;
-      UNUSED double f1mf42 = f1mf4*f1mf4;
+      double f12    = f1*f1;
+      double f42    = f4*f4;
+      double f1mf4  = f1-f4;
+      double f1mf42 = f1mf4*f1mf4;
 
       retVal = (-(d4*f1*f1mf4*f4) + f42*v1 + f12*v4 - 2*f1*f4*v4)/f1mf42;
       break;
     }
     case 1032:  // 2 freqs, points and derivatives: v1, v4, d1, d4
     {
-      UNUSED double f12 = f1*f1;
-      UNUSED double f13 = f12*f1;
-      UNUSED double f42 = f4*f4;
-      UNUSED double f43 = f42*f4;
+      double f12 = f1*f1;
+      double f13 = f12*f1;
+      double f42 = f4*f4;
+      double f43 = f42*f4;
 
-      UNUSED double f1mf4  = f1-f4;
-      UNUSED double f1mf42 = f1mf4*f1mf4;
-      UNUSED double f1mf43 = f1mf42*f1mf4;
+      double f1mf4  = f1-f4;
+      double f1mf42 = f1mf4*f1mf4;
+      double f1mf43 = f1mf42*f1mf4;
 
       retVal = (d4*f12*f4*(-f1 + f4) + d1*f1*(-f1 + f4)*f42 + 3*f1*f42*v1 - f43*v1 + f13*v4 - 3*f12*f4*v4)/f1mf43;
       break;
     }
     case 103:   // 4 freqs, no boundaries derivatives
     {
-      UNUSED double f12 = f1*f1;
-      UNUSED double f13 = f12*f1;
+      double f12 = f1*f1;
+      double f13 = f12*f1;
 
-      UNUSED double f22 = f2*f2;
-      UNUSED double f23 = f22*f2;
+      double f22 = f2*f2;
+      double f23 = f22*f2;
 
-      UNUSED double f32 = f3*f3;
-      UNUSED double f33 = f32*f3;
+      double f32 = f3*f3;
+      double f33 = f32*f3;
 
-      UNUSED double f42 = f4*f4;
-      UNUSED double f43 = f42*f4;
+      double f42 = f4*f4;
+      double f43 = f42*f4;
 
-      UNUSED double f1mf2 = f1-f2;
-      UNUSED double f1mf3 = f1-f3;
-      UNUSED double f1mf4 = f1-f4;
-      UNUSED double f2mf3 = f2-f3;
-      UNUSED double f2mf4 = f2-f4;
-      UNUSED double f3mf4 = f3-f4;
+      double f1mf2 = f1-f2;
+      double f1mf3 = f1-f3;
+      double f1mf4 = f1-f4;
+      double f2mf3 = f2-f3;
+      double f2mf4 = f2-f4;
+      double f3mf4 = f3-f4;
 
       retVal = (f1*f1mf3*f1mf4*f3*f3mf4*f4*v2 + f23*(f1*f1mf4*f4*v3 + f32*(-(f4*v1) + f1*v4) + f3*(f42*v1 - f12*v4)) + f2*(f12*f1mf4*f42*v3 + f33*(-(f42*v1) + f12*v4) + f32*(f43*v1 - f13*v4)) +
       f22*(f1*f4*(-f12 + f42)*v3 + f33*(f4*v1 - f1*v4) + f3*(-(f43*v1) + f13*v4)))/(f1mf2*f1mf3*f1mf4*f2mf3*f2mf4*f3mf4);
@@ -438,35 +789,33 @@ static double IMRPhenomXHM_Intermediate_Amp_delta0(double d1, double d4, double
     }
     case 1043:  //no left derivative
     {
-      UNUSED double f12 = f1*f1;
-      UNUSED double f13 = f12*f1;
-      UNUSED double f14 = f13*f1;
-
-      UNUSED double f22 = f2*f2;
-      UNUSED double f23 = f22*f2;
-      UNUSED double f24 = f23*f2;
-      UNUSED double f25 = f24*f2;
-
-      UNUSED double f32 = f3*f3;
-      UNUSED double f33 = f32*f3;
-      UNUSED double f34 = f33*f3;
-
-      UNUSED double f42 = f4*f4;
-      UNUSED double f43 = f42*f4;
-      UNUSED double f44 = f43*f4;
-      UNUSED double f45 = f44*f4;
-
-      UNUSED double f1mf2 = f1-f2;
-      UNUSED double f1mf3 = f1-f3;
-      UNUSED double f1mf4 = f1-f4;
-      UNUSED double f2mf3 = f2-f3;
-      UNUSED double f2mf4 = f2-f4;
-      UNUSED double f3mf4 = f3-f4;
-
-      UNUSED double f1mf42 = f1mf4*f1mf4;
-      UNUSED double f3mf42 = f3mf4*f3mf4;
-      UNUSED double f2mf32 = f2mf3*f2mf3;
-      UNUSED double f2mf42 = f2mf4*f2mf4;
+      double f12 = f1*f1;
+      double f13 = f12*f1;
+      double f14 = f13*f1;
+
+      double f22 = f2*f2;
+      double f23 = f22*f2;
+      double f24 = f23*f2;
+
+      double f32 = f3*f3;
+      double f33 = f32*f3;
+      double f34 = f33*f3;
+
+      double f42 = f4*f4;
+      double f43 = f42*f4;
+      double f44 = f43*f4;
+      double f45 = f44*f4;
+
+      double f1mf2 = f1-f2;
+      double f1mf3 = f1-f3;
+      double f1mf4 = f1-f4;
+      double f2mf3 = f2-f3;
+      double f2mf4 = f2-f4;
+      double f3mf4 = f3-f4;
+
+      double f1mf42 = f1mf4*f1mf4;
+      double f3mf42 = f3mf4*f3mf4;
+      double f2mf42 = f2mf4*f2mf4;
 
       retVal = (-(d4*f1*f1mf2*f1mf3*f1mf4*f2*f2mf3*f2mf4*f3*f3mf4*f4) - f1*f1mf3*f1mf42*f3*f3mf42*f42*v2 +
       f24*(-(f1*f1mf42*f42*v3) + f33*(f42*v1 + f12*v4 - 2*f1*f4*v4) + f3*f4*(f43*v1 + 2*f13*v4 - 3*f12*f4*v4) - f32*(2*f43*v1 + f13*v4 - 3*f1*f42*v4)) +
@@ -478,29 +827,29 @@ static double IMRPhenomXHM_Intermediate_Amp_delta0(double d1, double d4, double
     case 1042:   //4th order poly: v1,d1, v4,d4, v3  // used for the first intermediate region
     {
 
-      UNUSED double f12 = f1*f1;
-      UNUSED double f13 = f12*f1;
-      UNUSED double f14 = f13*f1;
-      UNUSED double f15 = f14*f1;
+      double f12 = f1*f1;
+      double f13 = f12*f1;
+      double f14 = f13*f1;
+      double f15 = f14*f1;
 
-      UNUSED double f42 = f4*f4;
-      UNUSED double f43 = f42*f4;
-      UNUSED double f44 = f43*f4;
-      UNUSED double f45 = f44*f4;
+      double f42 = f4*f4;
+      double f43 = f42*f4;
+      double f44 = f43*f4;
+      double f45 = f44*f4;
 
-      UNUSED double f32 = f3*f3;
-      UNUSED double f33 = f32*f3;
-      UNUSED double f34 = f33*f3;
+      double f32 = f3*f3;
+      double f33 = f32*f3;
+      double f34 = f33*f3;
 
-      UNUSED double f1mf4 = f1-f4;
-      UNUSED double f1mf3 = f1-f3;
-      UNUSED double f3mf4 = f3-f4;
+      double f1mf4 = f1-f4;
+      double f1mf3 = f1-f3;
+      double f3mf4 = f3-f4;
 
-      UNUSED double f1mf42 = f1mf4*f1mf4;
-      UNUSED double f1mf32 = f1mf3*f1mf3;
-      UNUSED double f3mf42 = f3mf4*f3mf4;
+      double f1mf42 = f1mf4*f1mf4;
+      double f1mf32 = f1mf3*f1mf3;
+      double f3mf42 = f3mf4*f3mf4;
 
-      UNUSED double f1mf43 = f1mf42*f1mf4;
+      double f1mf43 = f1mf42*f1mf4;
 
       retVal = (-(d4*f12*f1mf32*f1mf4*f3*f3mf4*f4) + d1*f1*f1mf3*f1mf4*f3*f3mf42*f42 - 4*f12*f33*f42*v1 + 3*f1*f34*f42*v1 + 8*f12*f32*f43*v1 - 4*f1*f33*f43*v1 - f34*f43*v1 - 4*f12*f3*f44*v1 - f1*f32*f44*v1 +
       2*f33*f44*v1 + 2*f1*f3*f45*v1 - f32*f45*v1 + f15*f42*v3 - 3*f14*f43*v3 + 3*f13*f44*v3 - f12*f45*v3 + f15*f32*v4 - 2*f14*f33*v4 + f13*f34*v4 - 2*f15*f3*f4*v4 + f14*f32*f4*v4 + 4*f13*f33*f4*v4 -
@@ -511,32 +860,17 @@ static double IMRPhenomXHM_Intermediate_Amp_delta0(double d1, double d4, double
     case 104:  //Geraint's Version, 4th order poly: v1,d1, v4,d4, v2
     {
 
-      UNUSED double f12 = f1*f1;
-      UNUSED double f13 = f12*f1;
-      UNUSED double f14 = f13*f1;
-
-      UNUSED double f22 = f2*f2;
-      UNUSED double f23 = f22*f2;
-      UNUSED double f24 = f23*f2;
-
-      UNUSED double f42 = f4*f4;
-      UNUSED double f43 = f42*f4;
-      UNUSED double f44 = f43*f4;
-
-      UNUSED double f1mf2 = f1-f2;
-      UNUSED double f1mf3 = f1-f3;
-      UNUSED double f1mf4 = f1-f4;
-      UNUSED double f2mf3 = f2-f3;
-      UNUSED double f2mf4 = f2-f4;
-      UNUSED double f3mf4 = f3-f4;
-
-      UNUSED double f1mf22 = f1mf2*f1mf2;
-      UNUSED double f1mf32 = f1mf3*f1mf3;
-      UNUSED double f1mf42 = f1mf4*f1mf4;
-      UNUSED double f2mf32 = f2mf3*f2mf3;
-      UNUSED double f2mf42 = f2mf4*f2mf4;
-      UNUSED double f3mf42 = f3mf4*f3mf4;
-      UNUSED double f1mf43 = f1mf4*f1mf4*f1mf4;
+      double f12 = f1*f1;
+
+      double f42 = f4*f4;
+
+      double f1mf2 = f1-f2;
+      double f1mf4 = f1-f4;
+      double f2mf4 = f2-f4;
+
+      double f1mf22 = f1mf2*f1mf2;
+      double f2mf42 = f2mf4*f2mf4;
+      double f1mf43 = f1mf4*f1mf4*f1mf4;
 
       retVal = ((-(d4*f12*f1mf22*f1mf4*f2*f2mf4*f4) + d1*f1*f1mf2*f1mf4*f2*f2mf42*f42 + f42*(f2*f2mf42*(-4*f12 + 3*f1*f2 + 2*f1*f4 - f2*f4)*v1 + f12*f1mf43*v2) +
       f12*f1mf22*f2*(f1*f2 - 2*f1*f4 - 3*f2*f4 + 4*f42)*v4)/(f1mf22*f1mf43*f2mf42));
@@ -544,48 +878,43 @@ static double IMRPhenomXHM_Intermediate_Amp_delta0(double d1, double d4, double
     }
     case 105: // Geraint, standard way: v1, v2, v3, v4, d1, d4
     {
-      UNUSED double f12 = f1*f1;
-      UNUSED double f13 = f12*f1;
-      UNUSED double f14 = f13*f1;
-      UNUSED double f15 = f14*f1;
-      UNUSED double f16 = f15*f1;
-      UNUSED double f17 = f16*f1;
-
-      UNUSED double f22 = f2*f2;
-      UNUSED double f23 = f22*f2;
-      UNUSED double f24 = f23*f2;
-      UNUSED double f25 = f24*f2;
-      UNUSED double f26 = f25*f2;
-      UNUSED double f27 = f26*f2;
-
-      UNUSED double f32 = f3*f3;
-      UNUSED double f33 = f32*f3;
-      UNUSED double f34 = f33*f3;
-      UNUSED double f35 = f34*f3;
-      UNUSED double f36 = f35*f3;
-      UNUSED double f37 = f36*f3;
-
-      UNUSED double f42 = f4*f4;
-      UNUSED double f43 = f42*f4;
-      UNUSED double f44 = f43*f4;
-      UNUSED double f45 = f44*f4;
-      UNUSED double f46 = f45*f4;
-      UNUSED double f47 = f46*f4;
-
-      UNUSED double f1mf2 = f1-f2;
-      UNUSED double f1mf3 = f1-f3;
-      UNUSED double f1mf4 = f1-f4;
-      UNUSED double f2mf3 = f2-f3;
-      UNUSED double f2mf4 = f2-f4;
-      UNUSED double f3mf4 = f3-f4;
-
-      UNUSED double f1mf22 = f1mf2*f1mf2;
-      UNUSED double f1mf32 = f1mf3*f1mf3;
-      UNUSED double f1mf42 = f1mf4*f1mf4;
-      UNUSED double f2mf32 = f2mf3*f2mf3;
-      UNUSED double f2mf42 = f2mf4*f2mf4;
-      UNUSED double f3mf42 = f3mf4*f3mf4;
-      UNUSED double f1mf43 = f1mf42*f1mf4;
+      double f12 = f1*f1;
+      double f13 = f12*f1;
+      double f14 = f13*f1;
+      double f15 = f14*f1;
+      double f16 = f15*f1;
+      double f17 = f16*f1;
+
+      double f22 = f2*f2;
+      double f23 = f22*f2;
+      double f24 = f23*f2;
+      double f25 = f24*f2;
+
+      double f32 = f3*f3;
+      double f33 = f32*f3;
+      double f34 = f33*f3;
+      double f35 = f34*f3;
+
+      double f42 = f4*f4;
+      double f43 = f42*f4;
+      double f44 = f43*f4;
+      double f45 = f44*f4;
+      double f46 = f45*f4;
+      double f47 = f46*f4;
+
+      double f1mf2 = f1-f2;
+      double f1mf3 = f1-f3;
+      double f1mf4 = f1-f4;
+      double f2mf3 = f2-f3;
+      double f2mf4 = f2-f4;
+      double f3mf4 = f3-f4;
+
+      double f1mf22 = f1mf2*f1mf2;
+      double f1mf32 = f1mf3*f1mf3;
+      double f1mf42 = f1mf4*f1mf4;
+      double f2mf42 = f2mf4*f2mf4;
+      double f3mf42 = f3mf4*f3mf4;
+      double f1mf43 = f1mf42*f1mf4;
 
       retVal = (
         (-(d4*f12*f1mf22*f1mf32*f1mf4*f2*f2mf3*f2mf4*f3*f3mf4*f4) - d1*f1*f1mf2*f1mf3*f1mf4*f2*f2mf3*f2mf42*f3*f3mf42*f42 + 5*f13*f24*f33*f42*v1 - 4*f12*f25*f33*f42*v1 - 5*f13*f23*f34*f42*v1 +
@@ -620,52 +949,52 @@ static double IMRPhenomXHM_Intermediate_Amp_delta1(double d1, double d4, double
   {
     case 101: //linear, only v1, v2
     {
-      UNUSED double f1mf4 = f1-f4;
+      double f1mf4 = f1-f4;
 
       retVal = (v1 - v4)/f1mf4;
       break;
     }
     case 102: //quadratic: v1, v2, d2
     {
-      UNUSED double f12 = f1*f1;
-      UNUSED double f42 = f4*f4;
-      UNUSED double f1mf42 = (f1-f4)*(f1-f4);
+      double f12 = f1*f1;
+      double f42 = f4*f4;
+      double f1mf42 = (f1-f4)*(f1-f4);
 
       retVal = (d4*(f12 - f42) + 2*f4*(-v1 + v4))/f1mf42;
       break;
     }
     case 1032:  // 2 freqs, points and derivatives: v1, v4, d1, d4
     {
-      UNUSED double f12 = f1*f1;
-      UNUSED double f42 = f4*f4;
+      double f12 = f1*f1;
+      double f42 = f4*f4;
 
-      UNUSED double f1mf4  = f1-f4;
-      UNUSED double f1mf42 = f1mf4*f1mf4;
-      UNUSED double f1mf43 = f1mf42*f1mf4;
+      double f1mf4  = f1-f4;
+      double f1mf42 = f1mf4*f1mf4;
+      double f1mf43 = f1mf42*f1mf4;
 
       retVal = (d4*f1*f1mf4*(f1 + 2*f4) - f4*(d1*(-2*f12 + f1*f4 + f42) + 6*f1*(v1 - v4)))/f1mf43;
       break;
     }
     case 103:   // 4 freqs, no boundaries derivatives
     {
-      UNUSED double f12 = f1*f1;
-      UNUSED double f13 = f12*f1;
+      double f12 = f1*f1;
+      double f13 = f12*f1;
 
-      UNUSED double f22 = f2*f2;
-      UNUSED double f23 = f22*f2;
+      double f22 = f2*f2;
+      double f23 = f22*f2;
 
-      UNUSED double f32 = f3*f3;
-      UNUSED double f33 = f32*f3;
+      double f32 = f3*f3;
+      double f33 = f32*f3;
 
-      UNUSED double f42 = f4*f4;
-      UNUSED double f43 = f42*f4;
+      double f42 = f4*f4;
+      double f43 = f42*f4;
 
-      UNUSED double f1mf2 = f1-f2;
-      UNUSED double f1mf3 = f1-f3;
-      UNUSED double f1mf4 = f1-f4;
-      UNUSED double f2mf3 = f2-f3;
-      UNUSED double f2mf4 = f2-f4;
-      UNUSED double f3mf4 = f3-f4;
+      double f1mf2 = f1-f2;
+      double f1mf3 = f1-f3;
+      double f1mf4 = f1-f4;
+      double f2mf3 = f2-f3;
+      double f2mf4 = f2-f4;
+      double f3mf4 = f3-f4;
 
       retVal = (f12*f1mf4*f42*(v2 - v3) + f33*(f42*(v1 - v2) + f12*(v2 - v4)) + f22*(f43*(v1 - v3) + f13*(v3 - v4) + f33*(-v1 + v4)) + f32*(f43*(-v1 + v2) + f13*(-v2 + v4)) +
       f23*(f42*(-v1 + v3) + f32*(v1 - v4) + f12*(-v3 + v4)))/(f1mf2*f1mf3*f1mf4*f2mf3*f2mf4*f3mf4);
@@ -673,40 +1002,39 @@ static double IMRPhenomXHM_Intermediate_Amp_delta1(double d1, double d4, double
     }
     case 1043:  //no left derivative
     {
-      UNUSED double f12 = f1*f1;
-      UNUSED double f13 = f12*f1;
-      UNUSED double f14 = f13*f1;
-
-      UNUSED double f22 = f2*f2;
-      UNUSED double f23 = f22*f2;
-      UNUSED double f24 = f23*f2;
-      UNUSED double f25 = f24*f2;
-
-      UNUSED double f32 = f3*f3;
-      UNUSED double f33 = f32*f3;
-      UNUSED double f34 = f33*f3;
-
-      UNUSED double f42 = f4*f4;
-      UNUSED double f43 = f42*f4;
-      UNUSED double f44 = f43*f4;
-
-      UNUSED double f1mf2 = f1-f2;
-      UNUSED double f1mf3 = f1-f3;
-      UNUSED double f1mf4 = f1-f4;
-      UNUSED double f2mf3 = f2-f3;
-      UNUSED double f2mf4 = f2-f4;
-      UNUSED double f3mf4 = f3-f4;
-
-      UNUSED double f1mf42 = f1mf4*f1mf4;
-      UNUSED double f2mf42 = f2mf4*f2mf4;
-      UNUSED double f3mf42 = f3mf4*f3mf4;
-
-      UNUSED double v1mv2 = v1-v2;
-      UNUSED double v2mv3 = v2-v3;
-      UNUSED double v2mv4 = v2-v4;
-      UNUSED double v1mv3 = v1-v3;
-      UNUSED double v1mv4 = v1-v4;
-      UNUSED double v3mv4 = v3-v4;
+      double f12 = f1*f1;
+      double f13 = f12*f1;
+      double f14 = f13*f1;
+
+      double f22 = f2*f2;
+      double f23 = f22*f2;
+      double f24 = f23*f2;
+
+      double f32 = f3*f3;
+      double f33 = f32*f3;
+      double f34 = f33*f3;
+
+      double f42 = f4*f4;
+      double f43 = f42*f4;
+      double f44 = f43*f4;
+
+      double f1mf2 = f1-f2;
+      double f1mf3 = f1-f3;
+      double f1mf4 = f1-f4;
+      double f2mf3 = f2-f3;
+      double f2mf4 = f2-f4;
+      double f3mf4 = f3-f4;
+
+      double f1mf42 = f1mf4*f1mf4;
+      double f2mf42 = f2mf4*f2mf4;
+      double f3mf42 = f3mf4*f3mf4;
+
+      double v1mv2 = v1-v2;
+      double v2mv3 = v2-v3;
+      double v2mv4 = v2-v4;
+      double v1mv3 = v1-v3;
+      double v1mv4 = v1-v4;
+      double v3mv4 = v3-v4;
 
       retVal =(d4*f1mf4*f2mf4*f3mf4*(f1*f2*f3 + f2*f3*f4 + f1*(f2 + f3)*f4) + (f4*(f12*f1mf42*f43*v2mv3 + f34*(f43*v1mv2 +
         3*f12*f4*v2mv4 + 2*f13*(-v2 + v4)) + f32*f4*(f44*v1mv2 + 4*f13*f4*v2mv4 + 3*f14*(-v2 + v4)) + 2*f33*(f44*(-v1 + v2)
@@ -718,33 +1046,29 @@ static double IMRPhenomXHM_Intermediate_Amp_delta1(double d1, double d4, double
     }
     case 1042:   //4th order poly: v1,d1, v4,d4, v3  // used for the first intermediate region
     {
-      UNUSED double f12 = f1*f1;
-      UNUSED double f13 = f12*f1;
-      UNUSED double f14 = f13*f1;
-      UNUSED double f15 = f14*f1;
+      double f12 = f1*f1;
+      double f13 = f12*f1;
+      double f14 = f13*f1;
+      double f15 = f14*f1;
 
-      UNUSED double f42 = f4*f4;
-      UNUSED double f43 = f42*f4;
-      UNUSED double f44 = f43*f4;
-      UNUSED double f45 = f44*f4;
+      double f42 = f4*f4;
+      double f43 = f42*f4;
+      double f44 = f43*f4;
+      double f45 = f44*f4;
 
-      UNUSED double f32 = f3*f3;
-      UNUSED double f33 = f32*f3;
-      UNUSED double f34 = f33*f3;
+      double f32 = f3*f3;
+      double f33 = f32*f3;
+      double f34 = f33*f3;
 
-      UNUSED double f1mf4 = f1-f4;
-      UNUSED double f1mf3 = f1-f3;
-      UNUSED double f3mf4 = f3-f4;
+      double f1mf4 = f1-f4;
+      double f1mf3 = f1-f3;
+      double f3mf4 = f3-f4;
 
-      UNUSED double f1mf42 = f1mf4*f1mf4;
-      UNUSED double f1mf32 = f1mf3*f1mf3;
-      UNUSED double f3mf42 = f3mf4*f3mf4;
+      double f1mf42 = f1mf4*f1mf4;
+      double f1mf32 = f1mf3*f1mf3;
+      double f3mf42 = f3mf4*f3mf4;
 
-      UNUSED double f1mf43 = f1mf42*f1mf4;
-
-      UNUSED double v1mv4 = v1-v4;
-      UNUSED double v1mv3 = v1-v3;
-      UNUSED double v3mv4 = v3-v4;
+      double f1mf43 = f1mf42*f1mf4;
 
       retVal = (d4*f15*f32 - 2*d4*f14*f33 + d4*f13*f34 + d4*f14*f32*f4 - 2*d1*f13*f33*f4 - 2*d4*f13*f33*f4 + 2*d1*f12*f34*f4 + d4*f12*f34*f4 - d4*f15*f42 + 3*d1*f13*f32*f42 + d4*f13*f32*f42 - 2*d1*f12*f33*f42 +
         2*d4*f12*f33*f42 - d1*f1*f34*f42 - 2*d4*f1*f34*f42 + d4*f14*f43 - d1*f12*f32*f43 - 3*d4*f12*f32*f43 + 2*d1*f1*f33*f43 + 2*d4*f1*f33*f43 - d1*f34*f43 - d1*f13*f44 - d1*f1*f32*f44 + 2*d1*f33*f44 +
@@ -770,36 +1094,25 @@ static double IMRPhenomXHM_Intermediate_Amp_delta1(double d1, double d4, double
       case 104:  //Geraint's Version, 4th order poly: v1,d1, v2,d2, v3
       {
 
-        UNUSED double f12 = f1*f1;
-        UNUSED double f13 = f12*f1;
-        UNUSED double f14 = f13*f1;
-
-        UNUSED double f22 = f2*f2;
-        UNUSED double f23 = f22*f2;
-        UNUSED double f24 = f23*f2;
-
-        UNUSED double f32 = f3*f3;
-        UNUSED double f33 = f32*f3;
-        UNUSED double f34 = f33*f3;
-
-        UNUSED double f42 = f4*f4;
-        UNUSED double f43 = f42*f4;
-        UNUSED double f44 = f43*f4;
-
-        UNUSED double f1mf2 = f1-f2;
-        UNUSED double f1mf3 = f1-f3;
-        UNUSED double f1mf4 = f1-f4;
-        UNUSED double f2mf3 = f2-f3;
-        UNUSED double f2mf4 = f2-f4;
-        UNUSED double f3mf4 = f3-f4;
-
-        UNUSED double f1mf22 = f1mf2*f1mf2;
-        UNUSED double f1mf32 = f1mf3*f1mf3;
-        UNUSED double f1mf42 = f1mf4*f1mf4;
-        UNUSED double f2mf32 = f2mf3*f2mf3;
-        UNUSED double f2mf42 = f2mf4*f2mf4;
-        UNUSED double f3mf42 = f3mf4*f3mf4;
-        UNUSED double f1mf43 = f1mf4*f1mf4*f1mf4;
+        double f12 = f1*f1;
+        double f13 = f12*f1;
+        double f14 = f13*f1;
+
+        double f22 = f2*f2;
+        double f23 = f22*f2;
+        double f24 = f23*f2;
+
+        double f42 = f4*f4;
+        double f43 = f42*f4;
+        double f44 = f43*f4;
+
+        double f1mf2 = f1-f2;
+        double f1mf4 = f1-f4;
+        double f2mf4 = f2-f4;
+
+        double f1mf22 = f1mf2*f1mf2;
+        double f2mf42 = f2mf4*f2mf4;
+        double f1mf43 = f1mf4*f1mf4*f1mf4;
 
         retVal = ((d4*f1*f1mf22*f1mf4*f2mf4*(2*f2*f4 + f1*(f2 + f4)) + f4*(-(d1*f1mf2*f1mf4*f2mf42*(2*f1*f2 + (f1 + f2)*f4)) -
         2*f1*(f44*(v1 - v2) + 3*f24*(v1 - v4) + f14*(v2 - v4) + 4*f23*f4*(-v1 + v4)
@@ -809,48 +1122,39 @@ static double IMRPhenomXHM_Intermediate_Amp_delta1(double d1, double d4, double
       case 105: // Geraint, standard way: v1, v2, v3, v4, d1, d4
       {
 
-        UNUSED double f12 = f1*f1;
-        UNUSED double f13 = f12*f1;
-        UNUSED double f14 = f13*f1;
-        UNUSED double f15 = f14*f1;
-        UNUSED double f16 = f15*f1;
-        UNUSED double f17 = f16*f1;
-
-        UNUSED double f22 = f2*f2;
-        UNUSED double f23 = f22*f2;
-        UNUSED double f24 = f23*f2;
-        UNUSED double f25 = f24*f2;
-        UNUSED double f26 = f25*f2;
-        UNUSED double f27 = f26*f2;
-
-        UNUSED double f32 = f3*f3;
-        UNUSED double f33 = f32*f3;
-        UNUSED double f34 = f33*f3;
-        UNUSED double f35 = f34*f3;
-        UNUSED double f36 = f35*f3;
-        UNUSED double f37 = f36*f3;
-
-        UNUSED double f42 = f4*f4;
-        UNUSED double f43 = f42*f4;
-        UNUSED double f44 = f43*f4;
-        UNUSED double f45 = f44*f4;
-        UNUSED double f46 = f45*f4;
-        UNUSED double f47 = f46*f4;
-
-        UNUSED double f1mf2 = f1-f2;
-        UNUSED double f1mf3 = f1-f3;
-        UNUSED double f1mf4 = f1-f4;
-        UNUSED double f2mf3 = f2-f3;
-        UNUSED double f2mf4 = f2-f4;
-        UNUSED double f3mf4 = f3-f4;
-
-        UNUSED double f1mf22 = f1mf2*f1mf2;
-        UNUSED double f1mf32 = f1mf3*f1mf3;
-        UNUSED double f1mf42 = f1mf4*f1mf4;
-        UNUSED double f2mf32 = f2mf3*f2mf3;
-        UNUSED double f2mf42 = f2mf4*f2mf4;
-        UNUSED double f3mf42 = f3mf4*f3mf4;
-        UNUSED double f1mf43 = f1mf4*f1mf4*f1mf4;
+        double f12 = f1*f1;
+        double f13 = f12*f1;
+        double f14 = f13*f1;
+        double f15 = f14*f1;
+        double f16 = f15*f1;
+
+        double f22 = f2*f2;
+        double f23 = f22*f2;
+        double f24 = f23*f2;
+        double f25 = f24*f2;
+
+        double f32 = f3*f3;
+        double f33 = f32*f3;
+        double f34 = f33*f3;
+        double f35 = f34*f3;
+
+        double f42 = f4*f4;
+        double f43 = f42*f4;
+        double f44 = f43*f4;
+        double f45 = f44*f4;
+
+        double f1mf2 = f1-f2;
+        double f1mf3 = f1-f3;
+        double f1mf4 = f1-f4;
+        double f2mf3 = f2-f3;
+        double f2mf4 = f2-f4;
+        double f3mf4 = f3-f4;
+
+        double f1mf22 = f1mf2*f1mf2;
+        double f1mf32 = f1mf3*f1mf3;
+        double f2mf42 = f2mf4*f2mf4;
+        double f3mf42 = f3mf4*f3mf4;
+        double f1mf43 = f1mf4*f1mf4*f1mf4;
 
         retVal = (
           (d4*f1*f1mf22*f1mf32*f1mf4*f2mf3*f2mf4*f3mf4*(f1*f2*f3 + 2*f2*f3*f4 + f1*(f2 + f3)*f4) +
@@ -889,44 +1193,44 @@ static double IMRPhenomXHM_Intermediate_Amp_delta2(double d1, double d4, double
       }
       case 102: //quadratic: v1, v2, d2
       {
-        UNUSED double f1mf4  = f1-f4;
-        UNUSED double f1mf42 = f1mf4*f1mf4;
+        double f1mf4  = f1-f4;
+        double f1mf42 = f1mf4*f1mf4;
 
         retVal = (-(d4*f1mf4) + v1 - v4)/f1mf42;
         break;
       }
       case 1032:  // 2 freqs, points and derivatives: v1, v4, d1, d4
       {
-        UNUSED double f12 = f1*f1;
-        UNUSED double f42 = f4*f4;
+        double f12 = f1*f1;
+        double f42 = f4*f4;
 
-        UNUSED double f1mf4  = f1-f4;
-        UNUSED double f1mf42 = f1mf4*f1mf4;
-        UNUSED double f1mf43 = f1mf42*f1mf4;
+        double f1mf4  = f1-f4;
+        double f1mf42 = f1mf4*f1mf4;
+        double f1mf43 = f1mf42*f1mf4;
 
         retVal = (-(d1*(f12 + f1*f4 - 2*f42)) + d4*(-2*f12 + f1*f4 + f42) + 3*(f1 + f4)*(v1 - v4))/f1mf43;
         break;
       }
       case 103:   // 4 freqs, no boundaries derivatives
       {
-        UNUSED double f12 = f1*f1;
-        UNUSED double f13 = f12*f1;
+        double f12 = f1*f1;
+        double f13 = f12*f1;
 
-        UNUSED double f22 = f2*f2;
-        UNUSED double f23 = f22*f2;
+        double f22 = f2*f2;
+        double f23 = f22*f2;
 
-        UNUSED double f32 = f3*f3;
-        UNUSED double f33 = f32*f3;
+        double f32 = f3*f3;
+        double f33 = f32*f3;
 
-        UNUSED double f42 = f4*f4;
-        UNUSED double f43 = f42*f4;
+        double f42 = f4*f4;
+        double f43 = f42*f4;
 
-        UNUSED double f1mf2 = f1-f2;
-        UNUSED double f1mf3 = f1-f3;
-        UNUSED double f1mf4 = f1-f4;
-        UNUSED double f2mf3 = f2-f3;
-        UNUSED double f2mf4 = f2-f4;
-        UNUSED double f3mf4 = f3-f4;
+        double f1mf2 = f1-f2;
+        double f1mf3 = f1-f3;
+        double f1mf4 = f1-f4;
+        double f2mf3 = f2-f3;
+        double f2mf4 = f2-f4;
+        double f3mf4 = f3-f4;
 
         retVal = (-(f1*f4*(f12 - f42)*(v2 - v3)) + f3*(f43*(v1 - v2) + f13*(v2 - v4)) + f23*(f4*(v1 - v3) + f1*(v3 - v4) + f3*(-v1 + v4)) + f33*(f4*(-v1 + v2) + f1*(-v2 + v4)) +
         f2*(f43*(-v1 + v3) + f33*(v1 - v4) + f13*(-v3 + v4)))/(f1mf2*f1mf3*f1mf4*f2mf3*f2mf4*f3mf4);
@@ -934,42 +1238,37 @@ static double IMRPhenomXHM_Intermediate_Amp_delta2(double d1, double d4, double
       }
       case 1043:  //no left derivative: v1, v2, v3, v4, d4
       {
-        UNUSED double f12 = f1*f1;
-        UNUSED double f13 = f12*f1;
-        UNUSED double f14 = f13*f1;
-
-        UNUSED double f22 = f2*f2;
-        UNUSED double f23 = f22*f2;
-        UNUSED double f24 = f23*f2;
-        UNUSED double f25 = f24*f2;
-        UNUSED double f26 = f25*f2;
-
-        UNUSED double f32 = f3*f3;
-        UNUSED double f33 = f32*f3;
-        UNUSED double f34 = f33*f3;
-
-        UNUSED double f42 = f4*f4;
-        UNUSED double f43 = f42*f4;
-        UNUSED double f44 = f43*f4;
-        UNUSED double f46 = f44*f42;
-
-        UNUSED double f1mf2 = f1-f2;
-        UNUSED double f1mf3 = f1-f3;
-        UNUSED double f1mf4 = f1-f4;
-        UNUSED double f2mf3 = f2-f3;
-        UNUSED double f2mf4 = f2-f4;
-        UNUSED double f3mf4 = f3-f4;
-
-        UNUSED double f1mf42 = f1mf4*f1mf4;
-        UNUSED double f2mf42 = f2mf4*f2mf4;
-        UNUSED double f3mf42 = f3mf4*f3mf4;
-
-        UNUSED double v1mv2 = v1-v2;
-        UNUSED double v2mv3 = v2-v3;
-        UNUSED double v2mv4 = v2-v4;
-        UNUSED double v1mv3 = v1-v3;
-        UNUSED double v1mv4 = v1-v4;
-        UNUSED double v3mv4 = v3-v4;
+        double f12 = f1*f1;
+        double f13 = f12*f1;
+        double f14 = f13*f1;
+
+        double f22 = f2*f2;
+        double f23 = f22*f2;
+        double f24 = f23*f2;
+
+        double f32 = f3*f3;
+        double f33 = f32*f3;
+        double f34 = f33*f3;
+
+        double f42 = f4*f4;
+        double f43 = f42*f4;
+        double f44 = f43*f4;
+        double f46 = f44*f42;
+
+        double f1mf2 = f1-f2;
+        double f1mf3 = f1-f3;
+        double f1mf4 = f1-f4;
+        double f2mf3 = f2-f3;
+        double f2mf4 = f2-f4;
+        double f3mf4 = f3-f4;
+
+        double f1mf42 = f1mf4*f1mf4;
+        double f2mf42 = f2mf4*f2mf4;
+        double f3mf42 = f3mf4*f3mf4;
+
+        double v1mv3 = v1-v3;
+        double v1mv4 = v1-v4;
+        double v3mv4 = v3-v4;
 
         retVal = (-(d4*f1mf2*f1mf3*f1mf4*f2mf3*f2mf4*f3mf4*(f3*f4 + f2*(f3 + f4) + f1*(f2 + f3 + f4))) - 2*f34*f43*v1 + 3*f33*f44*v1 - f3*f46*v1 - f14*f33*v2 + f13*f34*v2 + 3*f14*f3*f42*v2 - 3*f1*f34*f42*v2 -
         2*f14*f43*v2 - 4*f13*f3*f43*v2 + 4*f1*f33*f43*v2 + 2*f34*f43*v2 + 3*f13*f44*v2 - 3*f33*f44*v2 - f1*f46*v2 + f3*f46*v2 + 2*f14*f43*v3 - 3*f13*f44*v3 + f1*f46*v3 +
@@ -980,29 +1279,29 @@ static double IMRPhenomXHM_Intermediate_Amp_delta2(double d1, double d4, double
       }
       case 1042:   //4th order poly: v1,d1, v2,d2, v3   // used for the first intermediate region
       {
-        UNUSED double f12 = f1*f1;
-        UNUSED double f13 = f12*f1;
-        UNUSED double f14 = f13*f1;
-        UNUSED double f15 = f14*f1;
+        double f12 = f1*f1;
+        double f13 = f12*f1;
+        double f14 = f13*f1;
+        double f15 = f14*f1;
 
-        UNUSED double f42 = f4*f4;
-        UNUSED double f43 = f42*f4;
-        UNUSED double f44 = f43*f4;
-        UNUSED double f45 = f44*f4;
+        double f42 = f4*f4;
+        double f43 = f42*f4;
+        double f44 = f43*f4;
+        double f45 = f44*f4;
 
-        UNUSED double f32 = f3*f3;
-        UNUSED double f33 = f32*f3;
-        UNUSED double f34 = f33*f3;
+        double f32 = f3*f3;
+        double f33 = f32*f3;
+        double f34 = f33*f3;
 
-        UNUSED double f1mf4 = f1-f4;
-        UNUSED double f1mf3 = f1-f3;
-        UNUSED double f3mf4 = f3-f4;
+        double f1mf4 = f1-f4;
+        double f1mf3 = f1-f3;
+        double f3mf4 = f3-f4;
 
-        UNUSED double f1mf42 = f1mf4*f1mf4;
-        UNUSED double f1mf32 = f1mf3*f1mf3;
-        UNUSED double f3mf42 = f3mf4*f3mf4;
+        double f1mf42 = f1mf4*f1mf4;
+        double f1mf32 = f1mf3*f1mf3;
+        double f3mf42 = f3mf4*f3mf4;
 
-        UNUSED double f1mf43 = f1mf42*f1mf4;
+        double f1mf43 = f1mf42*f1mf4;
 
         retVal = (-(d4*f1mf32*f1mf4*f3mf4*(f12 + f3*f4 + 2*f1*(f3 + f4))) + d1*f1mf3*f1mf4*f3mf42*(f1*f3 + 2*(f1 + f3)*f4 + f42) - 4*f12*f33*v1 + 3*f1*f34*v1 - 4*f1*f33*f4*v1 + 3*f34*f4*v1 + 12*f12*f3*f42*v1 -
         4*f33*f42*v1 - 8*f12*f43*v1 + f1*f44*v1 + f45*v1 + f15*v3 + f14*f4*v3 - 8*f13*f42*v3 + 8*f12*f43*v3 - f1*f44*v3 - f45*v3 -
@@ -1011,38 +1310,27 @@ static double IMRPhenomXHM_Intermediate_Amp_delta2(double d1, double d4, double
       }
       case 104:  //Geraint's Version, 4th order poly: v1,d1, v2,d2, v3
       {
-        UNUSED double f12 = f1*f1;
-        UNUSED double f13 = f12*f1;
-        UNUSED double f14 = f13*f1;
-        UNUSED double f15 = f14*f1;
-
-        UNUSED double f22 = f2*f2;
-        UNUSED double f23 = f22*f2;
-        UNUSED double f24 = f23*f2;
-
-        UNUSED double f32 = f3*f3;
-        UNUSED double f33 = f32*f3;
-        UNUSED double f34 = f33*f3;
-
-        UNUSED double f42 = f4*f4;
-        UNUSED double f43 = f42*f4;
-        UNUSED double f44 = f43*f4;
-        UNUSED double f45 = f44*f4;
-
-        UNUSED double f1mf2 = f1-f2;
-        UNUSED double f1mf3 = f1-f3;
-        UNUSED double f1mf4 = f1-f4;
-        UNUSED double f2mf3 = f2-f3;
-        UNUSED double f2mf4 = f2-f4;
-        UNUSED double f3mf4 = f3-f4;
-
-        UNUSED double f1mf22 = f1mf2*f1mf2;
-        UNUSED double f1mf32 = f1mf3*f1mf3;
-        UNUSED double f1mf42 = f1mf4*f1mf4;
-        UNUSED double f2mf32 = f2mf3*f2mf3;
-        UNUSED double f2mf42 = f2mf4*f2mf4;
-        UNUSED double f3mf42 = f3mf4*f3mf4;
-        UNUSED double f1mf43 = f1mf4*f1mf4*f1mf4;
+        double f12 = f1*f1;
+        double f13 = f12*f1;
+        double f14 = f13*f1;
+        double f15 = f14*f1;
+
+        double f22 = f2*f2;
+        double f23 = f22*f2;
+        double f24 = f23*f2;
+
+        double f42 = f4*f4;
+        double f43 = f42*f4;
+        double f44 = f43*f4;
+        double f45 = f44*f4;
+
+        double f1mf2 = f1-f2;
+        double f1mf4 = f1-f4;
+        double f2mf4 = f2-f4;
+
+        double f1mf22 = f1mf2*f1mf2;
+        double f2mf42 = f2mf4*f2mf4;
+        double f1mf43 = f1mf4*f1mf4*f1mf4;
 
         retVal = ((-(d4*f1mf22*f1mf4*f2mf4*(f12 + f2*f4 + 2*f1*(f2 + f4))) + d1*f1mf2*f1mf4*f2mf42*(f1*f2 + 2*(f1 + f2)*f4 + f42)
         - 4*f12*f23*v1 + 3*f1*f24*v1 - 4*f1*f23*f4*v1 + 3*f24*f4*v1 + 12*f12*f2*f42*v1 -
@@ -1053,48 +1341,42 @@ static double IMRPhenomXHM_Intermediate_Amp_delta2(double d1, double d4, double
       }
       case 105: // Geraint, standard way: v1, v2, v3, v4, d1, d4
       {
-        UNUSED double f12 = f1*f1;
-        UNUSED double f13 = f12*f1;
-        UNUSED double f14 = f13*f1;
-        UNUSED double f15 = f14*f1;
-        UNUSED double f16 = f15*f1;
-        UNUSED double f17 = f16*f1;
-
-        UNUSED double f22 = f2*f2;
-        UNUSED double f23 = f22*f2;
-        UNUSED double f24 = f23*f2;
-        UNUSED double f25 = f24*f2;
-        UNUSED double f26 = f25*f2;
-        UNUSED double f27 = f26*f2;
-
-        UNUSED double f32 = f3*f3;
-        UNUSED double f33 = f32*f3;
-        UNUSED double f34 = f33*f3;
-        UNUSED double f35 = f34*f3;
-        UNUSED double f36 = f35*f3;
-        UNUSED double f37 = f36*f3;
-
-        UNUSED double f42 = f4*f4;
-        UNUSED double f43 = f42*f4;
-        UNUSED double f44 = f43*f4;
-        UNUSED double f45 = f44*f4;
-        UNUSED double f46 = f45*f4;
-        UNUSED double f47 = f46*f4;
-
-        UNUSED double f1mf2 = f1-f2;
-        UNUSED double f1mf3 = f1-f3;
-        UNUSED double f1mf4 = f1-f4;
-        UNUSED double f2mf3 = f2-f3;
-        UNUSED double f2mf4 = f2-f4;
-        UNUSED double f3mf4 = f3-f4;
-
-        UNUSED double f1mf22 = f1mf2*f1mf2;
-        UNUSED double f1mf32 = f1mf3*f1mf3;
-        UNUSED double f1mf42 = f1mf4*f1mf4;
-        UNUSED double f2mf32 = f2mf3*f2mf3;
-        UNUSED double f2mf42 = f2mf4*f2mf4;
-        UNUSED double f3mf42 = f3mf4*f3mf4;
-        UNUSED double f1mf43 = f1mf4*f1mf4*f1mf4;
+        double f12 = f1*f1;
+        double f13 = f12*f1;
+        double f14 = f13*f1;
+        double f15 = f14*f1;
+        double f16 = f15*f1;
+        double f17 = f16*f1;
+
+        double f22 = f2*f2;
+        double f23 = f22*f2;
+        double f24 = f23*f2;
+        double f25 = f24*f2;
+
+        double f32 = f3*f3;
+        double f33 = f32*f3;
+        double f34 = f33*f3;
+        double f35 = f34*f3;
+
+        double f42 = f4*f4;
+        double f43 = f42*f4;
+        double f44 = f43*f4;
+        double f45 = f44*f4;
+        double f46 = f45*f4;
+        double f47 = f46*f4;
+
+        double f1mf2 = f1-f2;
+        double f1mf3 = f1-f3;
+        double f1mf4 = f1-f4;
+        double f2mf3 = f2-f3;
+        double f2mf4 = f2-f4;
+        double f3mf4 = f3-f4;
+
+        double f1mf22 = f1mf2*f1mf2;
+        double f1mf32 = f1mf3*f1mf3;
+        double f2mf42 = f2mf4*f2mf4;
+        double f3mf42 = f3mf4*f3mf4;
+        double f1mf43 = f1mf4*f1mf4*f1mf4;
 
         retVal = (
           (-(d4*f1mf22*f1mf32*f1mf4*f2mf3*f2mf4*f3mf4*(f2*f3*f4 + f12*(f2 + f3 + f4) + 2*f1*(f2*f3 + (f2 + f3)*f4))) -
@@ -1142,33 +1424,29 @@ static double IMRPhenomXHM_Intermediate_Amp_delta3(double d1, double d4, double
       }
       case 1032:  // 2 freqs, points and derivatives: v1, v4, d1, d4
       {
-        UNUSED double f1mf4 = f1-f4;
-        UNUSED double f1mf42 = f1mf4*f1mf4;
-        UNUSED double f1mf43 = f1mf42*f1mf4;
+        double f1mf4 = f1-f4;
+        double f1mf42 = f1mf4*f1mf4;
+        double f1mf43 = f1mf42*f1mf4;
 
         retVal = (d1*f1mf4 + d4*f1mf4 - 2*v1 + 2*v4)/f1mf43;
         break;
       }
       case 103:  // 4 freqs, no boundaries derivatives
       {
-        UNUSED double f12 = f1*f1;
-        UNUSED double f13 = f12*f1;
+        double f12 = f1*f1;
 
-        UNUSED double f22 = f2*f2;
-        UNUSED double f23 = f22*f2;
+        double f22 = f2*f2;
 
-        UNUSED double f32 = f3*f3;
-        UNUSED double f33 = f32*f3;
+        double f32 = f3*f3;
 
-        UNUSED double f42 = f4*f4;
-        UNUSED double f43 = f42*f4;
+        double f42 = f4*f4;
 
-        UNUSED double f1mf2 = f1-f2;
-        UNUSED double f1mf3 = f1-f3;
-        UNUSED double f1mf4 = f1-f4;
-        UNUSED double f2mf3 = f2-f3;
-        UNUSED double f2mf4 = f2-f4;
-        UNUSED double f3mf4 = f3-f4;
+        double f1mf2 = f1-f2;
+        double f1mf3 = f1-f3;
+        double f1mf4 = f1-f4;
+        double f2mf3 = f2-f3;
+        double f2mf4 = f2-f4;
+        double f3mf4 = f3-f4;
 
         retVal = (f1*f1mf4*f4*(v2 - v3) + f32*(f4*(v1 - v2) + f1*(v2 - v4)) + f2*(f42*(v1 - v3) + f12*(v3 - v4) + f32*(-v1 + v4)) + f3*(f42*(-v1 + v2) + f12*(-v2 + v4)) +
         f22*(f4*(-v1 + v3) + f3*(v1 - v4) + f1*(-v3 + v4)))/(f1mf2*f1mf3*f1mf4*f2mf3*f2mf4*f3mf4);
@@ -1176,39 +1454,36 @@ static double IMRPhenomXHM_Intermediate_Amp_delta3(double d1, double d4, double
       }
       case 1043:  //no left derivative: v1, v2, v3, v4, d4
       {
-        UNUSED double f12 = f1*f1;
-        UNUSED double f13 = f12*f1;
-        UNUSED double f14 = f13*f1;
-
-        UNUSED double f22 = f2*f2;
-        UNUSED double f23 = f22*f2;
-        UNUSED double f24 = f23*f2;
-
-        UNUSED double f32 = f3*f3;
-        UNUSED double f34 = f32*f32;
-
-        UNUSED double f42 = f4*f4;
-        UNUSED double f43 = f42*f4;
-        UNUSED double f44 = f43*f4;
-        UNUSED double f45 = f44*f4;
-
-        UNUSED double f1mf2 = f1-f2;
-        UNUSED double f1mf3 = f1-f3;
-        UNUSED double f1mf4 = f1-f4;
-        UNUSED double f2mf3 = f2-f3;
-        UNUSED double f2mf4 = f2-f4;
-        UNUSED double f3mf4 = f3-f4;
-
-        UNUSED double f1mf42 = f1mf4*f1mf4;
-        UNUSED double f2mf42 = f2mf4*f2mf4;
-        UNUSED double f3mf42 = f3mf4*f3mf4;
-
-        UNUSED double v1mv2 = v1-v2;
-        UNUSED double v2mv3 = v2-v3;
-        UNUSED double v2mv4 = v2-v4;
-        UNUSED double v1mv3 = v1-v3;
-        UNUSED double v1mv4 = v1-v4;
-        UNUSED double v3mv4 = v3-v4;
+        double f12 = f1*f1;
+        double f13 = f12*f1;
+        double f14 = f13*f1;
+
+        double f22 = f2*f2;
+        double f23 = f22*f2;
+        double f24 = f23*f2;
+
+        double f32 = f3*f3;
+        double f34 = f32*f32;
+
+        double f42 = f4*f4;
+        double f43 = f42*f4;
+        double f44 = f43*f4;
+        double f45 = f44*f4;
+
+        double f1mf2 = f1-f2;
+        double f1mf3 = f1-f3;
+        double f1mf4 = f1-f4;
+        double f2mf3 = f2-f3;
+        double f2mf4 = f2-f4;
+        double f3mf4 = f3-f4;
+
+        double f1mf42 = f1mf4*f1mf4;
+        double f2mf42 = f2mf4*f2mf4;
+        double f3mf42 = f3mf4*f3mf4;
+
+        double v1mv3 = v1-v3;
+        double v1mv4 = v1-v4;
+        double v3mv4 = v3-v4;
 
         retVal = (d4*f1mf2*f1mf3*f1mf4*f2mf3*f2mf4*f3mf4*(f1 + f2 + f3 + f4) + f34*f42*v1 - 3*f32*f44*v1 + 2*f3*f45*v1 + f14*f32*v2 - f12*f34*v2 - 2*f14*f3*f4*v2 + 2*f1*f34*f4*v2 + f14*f42*v2 - f34*f42*v2 +
         4*f12*f3*f43*v2 - 4*f1*f32*f43*v2 - 3*f12*f44*v2 + 3*f32*f44*v2 + 2*f1*f45*v2 - 2*f3*f45*v2 - f14*f42*v3 + 3*f12*f44*v3 - 2*f1*f45*v3 +
@@ -1220,33 +1495,27 @@ static double IMRPhenomXHM_Intermediate_Amp_delta3(double d1, double d4, double
       case 1042:   //4th order poly: v1,d1, v2,d2, v3  // used for the first intermediate region
       {
 
-        UNUSED double f12 = f1*f1;
-        UNUSED double f13 = f12*f1;
-        UNUSED double f14 = f13*f1;
-        UNUSED double f15 = f14*f1;
+        double f12 = f1*f1;
+        double f13 = f12*f1;
+        double f14 = f13*f1;
 
-        UNUSED double f42 = f4*f4;
-        UNUSED double f43 = f42*f4;
-        UNUSED double f44 = f43*f4;
-        UNUSED double f45 = f44*f4;
+        double f42 = f4*f4;
+        double f43 = f42*f4;
+        double f44 = f43*f4;
 
-        UNUSED double f32 = f3*f3;
-        UNUSED double f33 = f32*f3;
-        UNUSED double f34 = f33*f3;
+        double f32 = f3*f3;
+        double f33 = f32*f3;
+        double f34 = f33*f3;
 
-        UNUSED double f1mf4 = f1-f4;
-        UNUSED double f1mf3 = f1-f3;
-        UNUSED double f3mf4 = f3-f4;
+        double f1mf4 = f1-f4;
+        double f1mf3 = f1-f3;
+        double f3mf4 = f3-f4;
 
-        UNUSED double f1mf42 = f1mf4*f1mf4;
-        UNUSED double f1mf32 = f1mf3*f1mf3;
-        UNUSED double f3mf42 = f3mf4*f3mf4;
+        double f1mf42 = f1mf4*f1mf4;
+        double f1mf32 = f1mf3*f1mf3;
+        double f3mf42 = f3mf4*f3mf4;
 
-        UNUSED double f1mf43 = f1mf42*f1mf4;
-
-        UNUSED double v1mv4 = v1-v4;
-        UNUSED double v1mv3 = v1-v3;
-        UNUSED double v3mv4 = v3-v4;
+        double f1mf43 = f1mf42*f1mf4;
 
         retVal = (2*d4*f14*f3 - d1*f13*f32 - 3*d4*f13*f32 + d1*f1*f34 + d4*f1*f34 - 2*d4*f14*f4 + 2*d1*f13*f3*f4 + 2*d4*f13*f3*f4 - d1*f12*f32*f4 + d4*f12*f32*f4 - d1*f34*f4 - d4*f34*f4 - d1*f13*f42 + d4*f13*f42 +
           2*d1*f12*f3*f42 - 2*d4*f12*f3*f42 - d1*f1*f32*f42 + d4*f1*f32*f42 - d1*f12*f43 + d4*f12*f43 - 2*d1*f1*f3*f43 - 2*d4*f1*f3*f43 + 3*d1*f32*f43 + d4*f32*f43 + 2*d1*f1*f44 - 2*d1*f3*f44 +
@@ -1257,36 +1526,25 @@ static double IMRPhenomXHM_Intermediate_Amp_delta3(double d1, double d4, double
         case 104:  //Geraint's Version, 4th order poly: v1,d1, v2,d2, v3
         {
 
-          UNUSED double f12 = f1*f1;
-          UNUSED double f13 = f12*f1;
-          UNUSED double f14 = f13*f1;
-
-          UNUSED double f22 = f2*f2;
-          UNUSED double f23 = f22*f2;
-          UNUSED double f24 = f23*f2;
-
-          UNUSED double f32 = f3*f3;
-          UNUSED double f33 = f32*f3;
-          UNUSED double f34 = f33*f3;
-
-          UNUSED double f42 = f4*f4;
-          UNUSED double f43 = f42*f4;
-          UNUSED double f44 = f43*f4;
-
-          UNUSED double f1mf2 = f1-f2;
-          UNUSED double f1mf3 = f1-f3;
-          UNUSED double f1mf4 = f1-f4;
-          UNUSED double f2mf3 = f2-f3;
-          UNUSED double f2mf4 = f2-f4;
-          UNUSED double f3mf4 = f3-f4;
-
-          UNUSED double f1mf22 = f1mf2*f1mf2;
-          UNUSED double f1mf32 = f1mf3*f1mf3;
-          UNUSED double f1mf42 = f1mf4*f1mf4;
-          UNUSED double f2mf32 = f2mf3*f2mf3;
-          UNUSED double f2mf42 = f2mf4*f2mf4;
-          UNUSED double f3mf42 = f3mf4*f3mf4;
-          UNUSED double f1mf43 = f1mf4*f1mf4*f1mf4;
+          double f12 = f1*f1;
+          double f13 = f12*f1;
+          double f14 = f13*f1;
+
+          double f22 = f2*f2;
+          double f23 = f22*f2;
+          double f24 = f23*f2;
+
+          double f42 = f4*f4;
+          double f43 = f42*f4;
+          double f44 = f43*f4;
+
+          double f1mf2 = f1-f2;
+          double f1mf4 = f1-f4;
+          double f2mf4 = f2-f4;
+
+          double f1mf22 = f1mf2*f1mf2;
+          double f2mf42 = f2mf4*f2mf4;
+          double f1mf43 = f1mf4*f1mf4*f1mf4;
 
           retVal = ((d4*f1mf22*f1mf4*f2mf4*(2*f1 + f2 + f4) - d1*f1mf2*f1mf4*f2mf42*(f1 + f2 + 2*f4)
           + 2*(f44*(-v1 + v2) + 2*f12*f2mf42*(v1 - v4) + 2*f22*f42*(v1 - v4)
@@ -1297,48 +1555,42 @@ static double IMRPhenomXHM_Intermediate_Amp_delta3(double d1, double d4, double
         }
         case 105: // Geraint, standard way: v1, v2, v3, v4, d1, d4
         {
-          UNUSED double f12 = f1*f1;
-          UNUSED double f13 = f12*f1;
-          UNUSED double f14 = f13*f1;
-          UNUSED double f15 = f14*f1;
-          UNUSED double f16 = f15*f1;
-          UNUSED double f17 = f16*f1;
-
-          UNUSED double f22 = f2*f2;
-          UNUSED double f23 = f22*f2;
-          UNUSED double f24 = f23*f2;
-          UNUSED double f25 = f24*f2;
-          UNUSED double f26 = f25*f2;
-          UNUSED double f27 = f26*f2;
-
-          UNUSED double f32 = f3*f3;
-          UNUSED double f33 = f32*f3;
-          UNUSED double f34 = f33*f3;
-          UNUSED double f35 = f34*f3;
-          UNUSED double f36 = f35*f3;
-          UNUSED double f37 = f36*f3;
-
-          UNUSED double f42 = f4*f4;
-          UNUSED double f43 = f42*f4;
-          UNUSED double f44 = f43*f4;
-          UNUSED double f45 = f44*f4;
-          UNUSED double f46 = f45*f4;
-          UNUSED double f47 = f46*f4;
-
-          UNUSED double f1mf2 = f1-f2;
-          UNUSED double f1mf3 = f1-f3;
-          UNUSED double f1mf4 = f1-f4;
-          UNUSED double f2mf3 = f2-f3;
-          UNUSED double f2mf4 = f2-f4;
-          UNUSED double f3mf4 = f3-f4;
-
-          UNUSED double f1mf22 = f1mf2*f1mf2;
-          UNUSED double f1mf32 = f1mf3*f1mf3;
-          UNUSED double f1mf42 = f1mf4*f1mf4;
-          UNUSED double f2mf32 = f2mf3*f2mf3;
-          UNUSED double f2mf42 = f2mf4*f2mf4;
-          UNUSED double f3mf42 = f3mf4*f3mf4;
-          UNUSED double f1mf43 = f1mf4*f1mf4*f1mf4;
+          double f12 = f1*f1;
+          double f13 = f12*f1;
+          double f14 = f13*f1;
+          double f15 = f14*f1;
+          double f16 = f15*f1;
+          double f17 = f16*f1;
+
+          double f22 = f2*f2;
+          double f23 = f22*f2;
+          double f24 = f23*f2;
+          double f25 = f24*f2;
+
+          double f32 = f3*f3;
+          double f33 = f32*f3;
+          double f34 = f33*f3;
+          double f35 = f34*f3;
+
+          double f42 = f4*f4;
+          double f43 = f42*f4;
+          double f44 = f43*f4;
+          double f45 = f44*f4;
+          double f46 = f45*f4;
+          double f47 = f46*f4;
+
+          double f1mf2 = f1-f2;
+          double f1mf3 = f1-f3;
+          double f1mf4 = f1-f4;
+          double f2mf3 = f2-f3;
+          double f2mf4 = f2-f4;
+          double f3mf4 = f3-f4;
+
+          double f1mf22 = f1mf2*f1mf2;
+          double f1mf32 = f1mf3*f1mf3;
+          double f2mf42 = f2mf4*f2mf4;
+          double f3mf42 = f3mf4*f3mf4;
+          double f1mf43 = f1mf4*f1mf4*f1mf4;
 
           retVal = (
             (d4*f1mf22*f1mf32*f1mf4*f2mf3*f2mf4*f3mf4*(f12 + f2*f3 + (f2 + f3)*f4 + 2*f1*(f2 + f3 + f4)) + d1*f1mf2*f1mf3*f1mf4*f2mf3*f2mf42*f3mf42*(f1*f2 + f1*f3 + f2*f3 + 2*(f1 + f2 + f3)*f4 + f42) -
@@ -1396,37 +1648,33 @@ static double IMRPhenomXHM_Intermediate_Amp_delta4(double d1, double d4, double
         }
         case 1043:  //no left derivative: v1, v2, v3, v4, d4
         {
-          UNUSED double f12 = f1*f1;
-          UNUSED double f13 = f12*f1;
-
-          UNUSED double f22 = f2*f2;
-          UNUSED double f23 = f22*f2;
-          UNUSED double f24 = f23*f2;
-
-          UNUSED double f32 = f3*f3;
-          UNUSED double f33 = f32*f3;
-
-          UNUSED double f42 = f4*f4;
-          UNUSED double f43 = f42*f4;
-          UNUSED double f44 = f43*f4;
-
-          UNUSED double f1mf2 = f1-f2;
-          UNUSED double f1mf3 = f1-f3;
-          UNUSED double f1mf4 = f1-f4;
-          UNUSED double f2mf3 = f2-f3;
-          UNUSED double f2mf4 = f2-f4;
-          UNUSED double f3mf4 = f3-f4;
-
-          UNUSED double f1mf42 = f1mf4*f1mf4;
-          UNUSED double f2mf42 = f2mf4*f2mf4;
-          UNUSED double f3mf42 = f3mf4*f3mf4;
-
-          UNUSED double v1mv2 = v1-v2;
-          UNUSED double v2mv3 = v2-v3;
-          UNUSED double v2mv4 = v2-v4;
-          UNUSED double v1mv3 = v1-v3;
-          UNUSED double v1mv4 = v1-v4;
-          UNUSED double v3mv4 = v3-v4;
+          double f12 = f1*f1;
+          double f13 = f12*f1;
+
+          double f22 = f2*f2;
+          double f23 = f22*f2;
+
+          double f32 = f3*f3;
+          double f33 = f32*f3;
+
+          double f42 = f4*f4;
+          double f43 = f42*f4;
+          double f44 = f43*f4;
+
+          double f1mf2 = f1-f2;
+          double f1mf3 = f1-f3;
+          double f1mf4 = f1-f4;
+          double f2mf3 = f2-f3;
+          double f2mf4 = f2-f4;
+          double f3mf4 = f3-f4;
+
+          double f1mf42 = f1mf4*f1mf4;
+          double f2mf42 = f2mf4*f2mf4;
+          double f3mf42 = f3mf4*f3mf4;
+
+          double v1mv3 = v1-v3;
+          double v1mv4 = v1-v4;
+          double v3mv4 = v3-v4;
 
           retVal = (-(d4*f1mf2*f1mf3*f1mf4*f2mf3*f2mf4*f3mf4) - f33*f42*v1 + 2*f32*f43*v1 - f3*f44*v1 - f13*f32*v2 + f12*f33*v2 + 2*f13*f3*f4*v2 - 2*f1*f33*f4*v2 - f13*f42*v2 - 3*f12*f3*f42*v2 + 3*f1*f32*f42*v2 +
           f33*f42*v2 + 2*f12*f43*v2 - 2*f32*f43*v2 - f1*f44*v2 + f3*f44*v2 + f13*f42*v3 - 2*f12*f43*v3 + f1*f44*v3 + f23*(f42*v1mv3 + f32*v1mv4 - 2*f3*f4*v1mv4 - f12*v3mv4 + 2*f1*f4*v3mv4) +
@@ -1436,29 +1684,24 @@ static double IMRPhenomXHM_Intermediate_Amp_delta4(double d1, double d4, double
         }
         case 1042:   //4th order poly: v1,d1, v2,d2, v3   // used for the first intermediate region
         {
-          UNUSED double f12 = f1*f1;
-          UNUSED double f13 = f12*f1;
-          UNUSED double f14 = f13*f1;
-          UNUSED double f15 = f14*f1;
+          double f12 = f1*f1;
+          double f13 = f12*f1;
 
-          UNUSED double f42 = f4*f4;
-          UNUSED double f43 = f42*f4;
-          UNUSED double f44 = f43*f4;
-          UNUSED double f45 = f44*f4;
+          double f42 = f4*f4;
+          double f43 = f42*f4;
 
-          UNUSED double f32 = f3*f3;
-          UNUSED double f33 = f32*f3;
-          UNUSED double f34 = f33*f3;
+          double f32 = f3*f3;
+          double f33 = f32*f3;
 
-          UNUSED double f1mf4 = f1-f4;
-          UNUSED double f1mf3 = f1-f3;
-          UNUSED double f3mf4 = f3-f4;
+          double f1mf4 = f1-f4;
+          double f1mf3 = f1-f3;
+          double f3mf4 = f3-f4;
 
-          UNUSED double f1mf42 = f1mf4*f1mf4;
-          UNUSED double f1mf32 = f1mf3*f1mf3;
-          UNUSED double f3mf42 = f3mf4*f3mf4;
+          double f1mf42 = f1mf4*f1mf4;
+          double f1mf32 = f1mf3*f1mf3;
+          double f3mf42 = f3mf4*f3mf4;
 
-          UNUSED double f1mf43 = f1mf42*f1mf4;
+          double f1mf43 = f1mf42*f1mf4;
 
           retVal = (-(d4*f1mf32*f1mf4*f3mf4) + d1*f1mf3*f1mf4*f3mf42 - 3*f1*f32*v1 + 2*f33*v1 + 6*f1*f3*f4*v1 - 3*f32*f4*v1 - 3*f1*f42*v1 + f43*v1 + f13*v3 - 3*f12*f4*v3 + 3*f1*f42*v3 - f43*v3 -
           f1mf32*(f1 + 2*f3 - 3*f4)*v4)/(f1mf32*f1mf43*f3mf42);
@@ -1466,36 +1709,22 @@ static double IMRPhenomXHM_Intermediate_Amp_delta4(double d1, double d4, double
         }
         case 104:  //Geraint's Version, 4th order poly: v1,d1, v2, v4,d4
         {
-          UNUSED double f12 = f1*f1;
-          UNUSED double f13 = f12*f1;
-          UNUSED double f14 = f13*f1;
-
-          UNUSED double f22 = f2*f2;
-          UNUSED double f23 = f22*f2;
-          UNUSED double f24 = f23*f2;
-
-          UNUSED double f32 = f3*f3;
-          UNUSED double f33 = f32*f3;
-          UNUSED double f34 = f33*f3;
-
-          UNUSED double f42 = f4*f4;
-          UNUSED double f43 = f42*f4;
-          UNUSED double f44 = f43*f4;
-
-          UNUSED double f1mf2 = f1-f2;
-          UNUSED double f1mf3 = f1-f3;
-          UNUSED double f1mf4 = f1-f4;
-          UNUSED double f2mf3 = f2-f3;
-          UNUSED double f2mf4 = f2-f4;
-          UNUSED double f3mf4 = f3-f4;
-
-          UNUSED double f1mf22 = f1mf2*f1mf2;
-          UNUSED double f1mf32 = f1mf3*f1mf3;
-          UNUSED double f1mf42 = f1mf4*f1mf4;
-          UNUSED double f2mf32 = f2mf3*f2mf3;
-          UNUSED double f2mf42 = f2mf4*f2mf4;
-          UNUSED double f3mf42 = f3mf4*f3mf4;
-          UNUSED double f1mf43 = f1mf4*f1mf4*f1mf4;
+          double f12 = f1*f1;
+          double f13 = f12*f1;
+
+          double f22 = f2*f2;
+          double f23 = f22*f2;
+
+          double f42 = f4*f4;
+          double f43 = f42*f4;
+
+          double f1mf2 = f1-f2;
+          double f1mf4 = f1-f4;
+          double f2mf4 = f2-f4;
+
+          double f1mf22 = f1mf2*f1mf2;
+          double f2mf42 = f2mf4*f2mf4;
+          double f1mf43 = f1mf4*f1mf4*f1mf4;
 
           retVal = ((-(d4*f1mf22*f1mf4*f2mf4) + d1*f1mf2*f1mf4*f2mf42 - 3*f1*f22*v1 + 2*f23*v1 + 6*f1*f2*f4*v1 - 3*f22*f4*v1
           - 3*f1*f42*v1 + f43*v1 + f13*v2 - 3*f12*f4*v2 + 3*f1*f42*v2 - f43*v2 - f1mf22*(f1 + 2*f2 - 3*f4)*v4)/(f1mf22*f1mf43*f2mf42));
@@ -1504,48 +1733,40 @@ static double IMRPhenomXHM_Intermediate_Amp_delta4(double d1, double d4, double
         }
         case 105: // Geraint, standard way: v1, v2, v3, v4, d1, d4
         {
-          UNUSED double f12 = f1*f1;
-          UNUSED double f13 = f12*f1;
-          UNUSED double f14 = f13*f1;
-          UNUSED double f15 = f14*f1;
-          UNUSED double f16 = f15*f1;
-          UNUSED double f17 = f16*f1;
-
-          UNUSED double f22 = f2*f2;
-          UNUSED double f23 = f22*f2;
-          UNUSED double f24 = f23*f2;
-          UNUSED double f25 = f24*f2;
-          UNUSED double f26 = f25*f2;
-          UNUSED double f27 = f26*f2;
-
-          UNUSED double f32 = f3*f3;
-          UNUSED double f33 = f32*f3;
-          UNUSED double f34 = f33*f3;
-          UNUSED double f35 = f34*f3;
-          UNUSED double f36 = f35*f3;
-          UNUSED double f37 = f36*f3;
-
-          UNUSED double f42 = f4*f4;
-          UNUSED double f43 = f42*f4;
-          UNUSED double f44 = f43*f4;
-          UNUSED double f45 = f44*f4;
-          UNUSED double f46 = f45*f4;
-          UNUSED double f47 = f46*f4;
-
-          UNUSED double f1mf2 = f1-f2;
-          UNUSED double f1mf3 = f1-f3;
-          UNUSED double f1mf4 = f1-f4;
-          UNUSED double f2mf3 = f2-f3;
-          UNUSED double f2mf4 = f2-f4;
-          UNUSED double f3mf4 = f3-f4;
-
-          UNUSED double f1mf22 = f1mf2*f1mf2;
-          UNUSED double f1mf32 = f1mf3*f1mf3;
-          UNUSED double f1mf42 = f1mf4*f1mf4;
-          UNUSED double f2mf32 = f2mf3*f2mf3;
-          UNUSED double f2mf42 = f2mf4*f2mf4;
-          UNUSED double f3mf42 = f3mf4*f3mf4;
-          UNUSED double f1mf43 = f1mf4*f1mf4*f1mf4;
+          double f12 = f1*f1;
+          double f13 = f12*f1;
+          double f14 = f13*f1;
+          double f15 = f14*f1;
+          double f16 = f15*f1;
+
+          double f22 = f2*f2;
+          double f23 = f22*f2;
+          double f24 = f23*f2;
+          double f25 = f24*f2;
+
+          double f32 = f3*f3;
+          double f33 = f32*f3;
+          double f34 = f33*f3;
+          double f35 = f34*f3;
+
+          double f42 = f4*f4;
+          double f43 = f42*f4;
+          double f44 = f43*f4;
+          double f45 = f44*f4;
+          double f46 = f45*f4;
+
+          double f1mf2 = f1-f2;
+          double f1mf3 = f1-f3;
+          double f1mf4 = f1-f4;
+          double f2mf3 = f2-f3;
+          double f2mf4 = f2-f4;
+          double f3mf4 = f3-f4;
+
+          double f1mf22 = f1mf2*f1mf2;
+          double f1mf32 = f1mf3*f1mf3;
+          double f2mf42 = f2mf4*f2mf4;
+          double f3mf42 = f3mf4*f3mf4;
+          double f1mf43 = f1mf4*f1mf4*f1mf4;
 
           retVal = (
             (-(d4*f1mf22*f1mf32*f1mf4*f2mf3*f2mf4*f3mf4*(2*f1 + f2 + f3 + f4)) - d1*f1mf2*f1mf3*f1mf4*f2mf3*f2mf42*f3mf42*(f1 + f2 + f3 + 2*f4) + 5*f13*f23*f32*v1 - 3*f1*f25*f32*v1 - 5*f13*f22*f33*v1 +
@@ -1618,48 +1839,36 @@ static double IMRPhenomXHM_Intermediate_Amp_delta5(double d1, double d4, double
         }
         case 105: // Geraint, standard way: v1, v2, v3, v4, d1, d4
         {
-          UNUSED double f12 = f1*f1;
-          UNUSED double f13 = f12*f1;
-          UNUSED double f14 = f13*f1;
-          UNUSED double f15 = f14*f1;
-          UNUSED double f16 = f15*f1;
-          UNUSED double f17 = f16*f1;
-
-          UNUSED double f22 = f2*f2;
-          UNUSED double f23 = f22*f2;
-          UNUSED double f24 = f23*f2;
-          UNUSED double f25 = f24*f2;
-          UNUSED double f26 = f25*f2;
-          UNUSED double f27 = f26*f2;
-
-          UNUSED double f32 = f3*f3;
-          UNUSED double f33 = f32*f3;
-          UNUSED double f34 = f33*f3;
-          UNUSED double f35 = f34*f3;
-          UNUSED double f36 = f35*f3;
-          UNUSED double f37 = f36*f3;
-
-          UNUSED double f42 = f4*f4;
-          UNUSED double f43 = f42*f4;
-          UNUSED double f44 = f43*f4;
-          UNUSED double f45 = f44*f4;
-          UNUSED double f46 = f45*f4;
-          UNUSED double f47 = f46*f4;
-
-          UNUSED double f1mf2 = f1-f2;
-          UNUSED double f1mf3 = f1-f3;
-          UNUSED double f1mf4 = f1-f4;
-          UNUSED double f2mf3 = f2-f3;
-          UNUSED double f2mf4 = f2-f4;
-          UNUSED double f3mf4 = f3-f4;
-
-          UNUSED double f1mf22 = f1mf2*f1mf2;
-          UNUSED double f1mf32 = f1mf3*f1mf3;
-          UNUSED double f1mf42 = f1mf4*f1mf4;
-          UNUSED double f2mf32 = f2mf3*f2mf3;
-          UNUSED double f2mf42 = f2mf4*f2mf4;
-          UNUSED double f3mf42 = f3mf4*f3mf4;
-          UNUSED double f1mf43 = f1mf4*f1mf4*f1mf4;
+          double f12 = f1*f1;
+          double f13 = f12*f1;
+          double f14 = f13*f1;
+          double f15 = f14*f1;
+
+          double f22 = f2*f2;
+          double f23 = f22*f2;
+          double f24 = f23*f2;
+
+          double f32 = f3*f3;
+          double f33 = f32*f3;
+          double f34 = f33*f3;
+
+          double f42 = f4*f4;
+          double f43 = f42*f4;
+          double f44 = f43*f4;
+          double f45 = f44*f4;
+
+          double f1mf2 = f1-f2;
+          double f1mf3 = f1-f3;
+          double f1mf4 = f1-f4;
+          double f2mf3 = f2-f3;
+          double f2mf4 = f2-f4;
+          double f3mf4 = f3-f4;
+
+          double f1mf22 = f1mf2*f1mf2;
+          double f1mf32 = f1mf3*f1mf3;
+          double f2mf42 = f2mf4*f2mf4;
+          double f3mf42 = f3mf4*f3mf4;
+          double f1mf43 = f1mf4*f1mf4*f1mf4;
 
           retVal = (
             (d4*f1mf22*f1mf32*f1mf4*f2mf3*f2mf4*f3mf4 + d1*f1mf2*f1mf3*f1mf4*f2mf3*f2mf42*f3mf42 - 4*f12*f23*f32*v1 + 3*f1*f24*f32*v1 + 4*f12*f22*f33*v1 - 2*f24*f33*v1 - 3*f1*f22*f34*v1 + 2*f23*f34*v1 +
@@ -1688,8 +1897,20 @@ static double IMRPhenomXHM_Intermediate_Amp_delta5(double d1, double d4, double
 /*********************************************/
 
 // Build the polynomial with the coefficients given and return the inverse of the polynomial (this is the ansatz)
-static double IMRPhenomXHM_Intermediate_Amp_Ansatz(IMRPhenomX_UsefulPowers *powers_of_f, IMRPhenomXHMAmpCoefficients *pAmp)
+static double IMRPhenomXHM_Intermediate_Amp_Ansatz(IMRPhenomX_UsefulPowers *powers_of_f, IMRPhenomXHMWaveformStruct *pWFHM, IMRPhenomXHMAmpCoefficients *pAmp)
 {
+    if(pWFHM->IMRPhenomXHMReleaseVersion != 122019){ 
+        double result = 0., fpower = 1.;
+        /* Ansatz = f^(-7/6) * polynomial */
+        for (UINT2 i = 0; i < pAmp->nCoefficientsInter; i++){
+            //printf("pAmp->nCoefficientsInter = %i, pAmp->InterCoefficient[%i] = %.16e\n", pAmp->nCoefficientsInter, i, pAmp->InterCoefficient[i]);
+            result += (pAmp->InterCoefficient[i] * fpower);
+            fpower *= powers_of_f->itself;
+        }
+        result *= powers_of_f->m_seven_sixths;
+        return result;
+    }
+    else{
         double a0 = pAmp->delta0;
         double a1 = pAmp->delta1;
         double a2 = pAmp->delta2;
@@ -1760,7 +1981,8 @@ static double IMRPhenomXHM_Intermediate_Amp_Ansatz(IMRPhenomX_UsefulPowers *powe
             XLAL_ERROR_REAL8(XLAL_EINVAL, "Error in IMRPhenomXHM_Intermediate_Amp_Ansatz: InterAmpPolOrder is not valid.\n");
           }
         }
-        return 1. / polynomial;
+        return pAmp->ampNorm / polynomial;
+    }
 }
 
 
@@ -2211,6 +2433,201 @@ void ChoosePolOrder(IMRPhenomXHMWaveformStruct *pWFHM, IMRPhenomXHMAmpCoefficien
     }
 }
 
+static void IMRPhenomXHM_Intermediate_Amp_CollocationPoints(IMRPhenomXHMAmpCoefficients *pAmp, IMRPhenomXHMWaveformStruct *pWFHM, IMRPhenomXWaveformStruct *pWF22, IMRPhenomXHMPhaseCoefficients *pPhase, IMRPhenomXAmpCoefficients *pAmp22, IMRPhenomXPhaseCoefficients *pPhase22){
+
+
+    /* Define collocation points frequencies */
+    switch(pWFHM->IMRPhenomXHMIntermediateAmpFreqsVersion){
+        case 0:{ // Equispaced. Get boundaries too
+            REAL8 deltaf = (pAmp->fAmpMatchIM - pAmp->fAmpMatchIN) / (pWFHM->nCollocPtsInterAmp - 1);
+            UINT2 idx = 0;
+            for (UINT2 i = 0; i < pWFHM->nCollocPtsInterAmp; i++){
+                if(pAmp->VersionCollocPtsInter[i] == 1){
+                    // Add point
+                    pAmp->CollocationPointsFreqsAmplitudeInter[idx] = pAmp->fAmpMatchIN + deltaf * i;
+                }
+                else if (pAmp->VersionCollocPtsInter[i] == 2){
+                    // Add point + derivative
+                    pAmp->CollocationPointsFreqsAmplitudeInter[idx] = pAmp->fAmpMatchIN + deltaf * i;
+                    pAmp->CollocationPointsFreqsAmplitudeInter[idx + 1] = pAmp->CollocationPointsFreqsAmplitudeInter[idx];
+                }
+                idx += pAmp->VersionCollocPtsInter[i];
+            }
+            break;
+        }
+        case 1:{ // Chebyshev. Get boundaries too
+            REAL8 semisum = 0.5 * (pAmp->fAmpMatchIN + pAmp->fAmpMatchIM);
+            REAL8 semidif = 0.5 * (pAmp->fAmpMatchIM - pAmp->fAmpMatchIN);
+            for (INT4 i = pWFHM->nCollocPtsInterAmp + 1; i >=0; i--){
+                pAmp->CollocationPointsFreqsAmplitudeInter[i] = semisum + semidif * cos( i * LAL_PI / pWFHM->nCollocPtsInterAmp );
+            }
+            break;
+        }
+        default: {XLAL_ERROR_VOID(XLAL_EDOM, "Error in IMRPhenomXHM_Intermediate_Amp_CollocationPoints: IMRPhenomXHMIntermediateAmpFreqsVersion = %i is not valid. \n", pWFHM->IMRPhenomXHMInspiralAmpFreqsVersion);}
+    }
+    /* Define values */
+
+    IMRPhenomX_UsefulPowers powers_of_finsp;
+    IMRPhenomX_Initialize_Powers(&powers_of_finsp, pAmp->fAmpMatchIN);
+    // Be careful with TGR thing. Inspiral affecting intermediate region.
+    UINT2 tmp_factor = pAmp->InspRescaleFactor;
+    pAmp->InspRescaleFactor = pAmp->InterRescaleFactor;
+    UINT2 tmpnCollocPts = 0;
+    if (pAmp->VersionCollocPtsInter[0] == 1){
+        pAmp->CollocationPointsValuesAmplitudeInter[0] = IMRPhenomXHM_Inspiral_Amp_Ansatz(&powers_of_finsp, pWFHM, pAmp);//FIXME: Rescale with InterFactor
+        tmpnCollocPts += 1;
+    }
+    else if (pAmp->VersionCollocPtsInter[0] == 2){
+        pAmp->CollocationPointsValuesAmplitudeInter[0] = IMRPhenomXHM_Inspiral_Amp_Ansatz(&powers_of_finsp, pWFHM, pAmp);
+        pAmp->CollocationPointsValuesAmplitudeInter[1] = IMRPhenomXHM_Inspiral_Amp_NDAnsatz(&powers_of_finsp, pWFHM, pAmp);//pAmp->CollocationPointsValuesAmplitudeInsp[2];
+        tmpnCollocPts += 2;
+    }
+    pAmp->InspRescaleFactor = tmp_factor;
+
+    /* Call parameter space fits */
+    /* pWFHM->nCollocPtsInterAmp also includes the boundaries, for the parameter space fits we just need the in between points */
+    UINT2 idx = 0;
+    for(UINT2 i = 1; i < pWFHM->nCollocPtsInterAmp - 1; i++){
+        if(i <= 2)
+            idx = pWFHM->modeInt * 2 + i - 1;
+        else
+            idx = pWFHM->modeInt * 2 + i - 3 + 16; //FIXME
+        if(pAmp->VersionCollocPtsInter[i] == 1){
+            pAmp->CollocationPointsValuesAmplitudeInter[tmpnCollocPts] = fabs(pAmp->IntermediateAmpFits[idx](pWF22, pWFHM->IMRPhenomXHMIntermediateAmpFitsVersion)); //FIXME: negative fits?
+            tmpnCollocPts++;
+        }
+        // FIXME: throw error here if pAmp->VersionCollocPtsInter[i] == 2, cannot use derivatives if you don't have the parameter space fit
+    }
+    
+    tmp_factor = pAmp->RDRescaleFactor;
+    pAmp->RDRescaleFactor = pAmp->InterRescaleFactor;
+    IMRPhenomX_UsefulPowers powers_of_fRD;
+    IMRPhenomX_Initialize_Powers(&powers_of_fRD, pAmp->fAmpMatchIM);
+    switch(pAmp->VersionCollocPtsInter[pWFHM->nCollocPtsInterAmp - 1]){
+        case 1:{ // Add point
+            if (pWFHM->MixingOn == 0){
+                pAmp->CollocationPointsValuesAmplitudeInter[tmpnCollocPts] = IMRPhenomXHM_RD_Amp_Ansatz(&powers_of_fRD, pWFHM, pAmp);//pAmp->CollocationPointsValuesAmplitudeRD[0];
+            }
+            else{
+                pAmp->CollocationPointsValuesAmplitudeInter[tmpnCollocPts] = cabs(SpheroidalToSpherical(&powers_of_fRD, pAmp22, pPhase22, pAmp, pPhase, pWFHM, pWF22));
+            }
+            tmpnCollocPts++;
+            break;
+        }
+        case 2:{ // Add point + derivative
+            if (pWFHM->MixingOn == 0){
+                pAmp->CollocationPointsValuesAmplitudeInter[tmpnCollocPts] = IMRPhenomXHM_RD_Amp_Ansatz(&powers_of_fRD, pWFHM, pAmp);//pAmp->CollocationPointsValuesAmplitudeRD[0];
+                pAmp->CollocationPointsValuesAmplitudeInter[tmpnCollocPts + 1] = IMRPhenomXHM_RD_Amp_DAnsatz(&powers_of_fRD, pWFHM, pAmp);//pAmp->CollocationPointsValuesAmplitudeRD[0];
+            }
+            else{
+                pAmp->CollocationPointsValuesAmplitudeInter[tmpnCollocPts] = cabs(SpheroidalToSpherical(&powers_of_fRD, pAmp22, pPhase22, pAmp, pPhase, pWFHM, pWF22));
+                pAmp->CollocationPointsValuesAmplitudeInter[tmpnCollocPts + 1] = IMRPhenomXHM_RD_Amp_NDAnsatz(&powers_of_fRD, pAmp, pPhase, pWFHM, pAmp22, pPhase22, pWF22);
+            }
+            tmpnCollocPts += 2;
+            break;
+        }
+        default: {XLALPrintError("Error in IMRPhenomXHM_Intermediate_Amp_Coefficients: version %i is not valid.", pAmp->VersionCollocPtsInter[pAmp->nCoefficientsInter - 1]);}
+    }
+    pAmp->RDRescaleFactor = tmp_factor;
+
+    /* tmpnCollocPts must be the same tahn pWFHM->nCollocPtsInterAmp + 2 (=number of free coefficients in intermediate ansatz) */
+    if(tmpnCollocPts != pAmp->nCoefficientsInter)
+        XLAL_ERROR_VOID(XLAL_EFUNC, "IMRPhenomXHM_Intermediate_Amp_CollocationPoints failed. Inconsistent number of free parameters %i, %i.", tmpnCollocPts, pAmp->nCoefficientsInter);
+}
+
+void IMRPhenomXHM_Intermediate_Amp_Coefficients(IMRPhenomXHMAmpCoefficients *pAmp, IMRPhenomXHMWaveformStruct *pWFHM, IMRPhenomXWaveformStruct *pWF22, IMRPhenomXHMPhaseCoefficients *pPhase, IMRPhenomXAmpCoefficients *pAmp22, IMRPhenomXPhaseCoefficients *pPhase22){
+
+    /* Previously we checked that nCollocPtsInterAmp read from the IMRPhenomXHMIntermediateAmpVersion is equal to the number of free coefficients in the ansatz. */
+    UINT2 nCollocPtsInterAmp = pAmp->nCoefficientsInter;
+
+    /* Define set of collocation points */
+    IMRPhenomXHM_Intermediate_Amp_CollocationPoints(pAmp, pWFHM, pWF22, pPhase, pAmp22, pPhase22);
+
+    /* GSL objects for solving system of equations via LU decomposition */
+    gsl_vector *b, *x;
+    gsl_matrix *A;
+    gsl_permutation *p;
+    int signum; // No need to set, used internally by gsl_linalg_LU_decomp
+
+    /* Initialize gsl objects */
+    p = gsl_permutation_alloc(nCollocPtsInterAmp);
+    b = gsl_vector_alloc(nCollocPtsInterAmp);
+    x = gsl_vector_alloc(nCollocPtsInterAmp);
+    A = gsl_matrix_alloc(nCollocPtsInterAmp, nCollocPtsInterAmp);
+
+
+    /* Define linear system of equations: A x = b */
+    /* x is the solution vector: the coefficients of the intermediate ansatz */
+    /* b is the vector of collocation points for a set of frequencies */
+    /* A is the matrix of multiplicative factors to each coefficient of the ansatz.
+       Each row gives the ansatz evaluated at a collocation point frequency. */
+    UINT2 tmpnCollocPts = 0;
+    for(UINT2 i = 0; i < pWFHM->nCollocPtsInterAmp; i++){
+        /* Skip the 0 cases, means that collocation point is not used */
+        if(pAmp->VersionCollocPtsInter[i] > 0){
+            // Set b vector
+            gsl_vector_set(b, tmpnCollocPts, pAmp->CollocationPointsValuesAmplitudeInter[tmpnCollocPts]);
+            //FIXME: distinguish InterAmp ansatzaes versions
+            // Set system matrix: Polynomial/f^7/6 at the collocation points frequencies.
+            /* A = (1, f1, f1^2, f1^3, f1^4, ...) * f1^(-7/6)
+                   (1, f2, f2^2, f2^3, f2^4, ...) * f2^(-7/6)
+                   ....
+                   Until number of collocation points
+              If one of the conditions is a derivative we substitute by
+                   (0, 1, 2*fi, 3*fi^2, 4*fi^3, ...)
+            */
+            REAL8 fcollpoint = pAmp->CollocationPointsFreqsAmplitudeInter[tmpnCollocPts];
+            REAL8 seven_sixths = 7/6.;
+            REAL8 fcollpoint_m_seven_sixths = pow(fcollpoint, -seven_sixths);
+            REAL8 fpower = 1.; // 1, f, f^2, f^3, f^4, ...
+
+            // Add equation for Point. Assuming I will always use point, not the derivative alone
+            for(INT4 j = 0; j < nCollocPtsInterAmp; j++){
+              gsl_matrix_set(A, tmpnCollocPts, j, fpower * fcollpoint_m_seven_sixths);
+              fpower *= fcollpoint;
+            }
+            tmpnCollocPts++;
+            // Add equation for Derivative
+            if (pAmp->VersionCollocPtsInter[i] == 2 ){
+              gsl_vector_set(b, tmpnCollocPts, pAmp->CollocationPointsValuesAmplitudeInter[tmpnCollocPts]);
+              fpower = 1./fcollpoint;
+              for(INT4 j = 0; j < nCollocPtsInterAmp; j++){
+                  REAL8 derivative = (j - seven_sixths) * fpower * fcollpoint_m_seven_sixths;
+                  gsl_matrix_set(A, tmpnCollocPts, j, derivative);
+                  fpower *= fcollpoint;
+              }
+              tmpnCollocPts++;
+            }
+        } /* End non-zero if statement */
+    } /* End of loop over number of free coefficients. System of equations setup. */
+
+    /* tmpnCollocPts must be the same than the number of free coefficients and to pAmp->nCoefficientsInter */
+    if (tmpnCollocPts != pAmp->nCoefficientsInter ){
+        /* Free gsl variables */
+        gsl_vector_free(b);
+        gsl_vector_free(x);
+        gsl_matrix_free(A);
+        gsl_permutation_free(p);
+        XLAL_ERROR_VOID(XLAL_EFUNC, "IMRPhenomXHM_Intermediate_Amp_Coefficients failed. Inconsistent number of collocation points (%i) and free parameters (%i).", tmpnCollocPts, pAmp->nCoefficientsInter);
+    }
+
+    /* We now solve the system A x = b via an LU decomposition. x is the solution vector */
+    gsl_linalg_LU_decomp(A, p, &signum);
+    gsl_linalg_LU_solve(A, p, b, x);
+
+    /* The solution corresponds to the coefficients of the ansatz */
+    for (UINT2 i = 0; i < pAmp->nCoefficientsInter; i++){
+        pAmp->InterCoefficient[i] = gsl_vector_get(x, i);
+    }
+
+    /* Free gsl variables */
+    gsl_vector_free(b);
+    gsl_vector_free(x);
+    gsl_matrix_free(A);
+    gsl_permutation_free(p);
+
+}
+
 
 /***********************************************/
 /*                                             */
@@ -2220,24 +2637,26 @@ void ChoosePolOrder(IMRPhenomXHMWaveformStruct *pWFHM, IMRPhenomXHMAmpCoefficien
 
 // Fits of phase derivatives at collocation points for each mode
 
-static double IMRPhenomXHM_Inter_Phase_21_p1(double eta, double S, double chi1, double chi2, int InterPhaseFlag) {
-    UNUSED double total=0,eta2,eta3,eta4,eta5,eta6,eta7,S2,S3,S4;
-    //double delta=sqrt(1-4.*eta);
+/* Start of Phase Parameter Space Fits */
+
+static double IMRPhenomXHM_Inter_Phase_21_p1(IMRPhenomXWaveformStruct *pWF, int InterPhaseFlag) {
+    double total=0;
     switch (InterPhaseFlag){
         case 122019:{
-
+            double eta = pWF->eta;
+            double S = pWF->STotR;
+            double eta2,eta3,eta4,eta5,eta6,S2,S3,S4;
             eta2 = pow(eta,2);
             eta3 = pow(eta,3);
             eta4 = pow(eta,4);
             eta5 = pow(eta,5);
             eta6 = pow(eta,6);
-            eta7 = pow(eta,7);
             S2 = pow(S,2);
             S3 = pow(S,3);
             S4 = pow(S,4);
             double noSpin = 4045.84 + 7.63226/eta - 1956.93*eta - 23428.1*eta2 + 369153.*eta3 - 2.28832e6*eta4 + 6.82533e6*eta5 - 7.86254e6*eta6;
             double eqSpin = - 347.273*S + 83.5428*S2 - 355.67*S3 + (4.44457*S + 16.5548*S2 + 13.6971*S3)/eta + eta*( - 79.761*S - 355.299*S2 + 1114.51*S3 - 1077.75*S4) + 92.6654*S4 + eta2*(- 619.837*S - 722.787*S2 + 2392.73*S3 + 2689.18*S4);
-            double uneqSpin =  ( 918.976*chi1*sqrt(1. - 4.*eta) - 918.976*chi2*sqrt(1. - 4.*eta))*eta + ( 91.7679*chi1*sqrt(1. - 4.*eta) - 91.7679*chi2*sqrt(1. - 4.*eta))*eta2;
+            double uneqSpin =  ( 918.976*pWF->chi1L*sqrt(1.-4.*eta) - 918.976*pWF->chi2L*sqrt(1.-4.*eta))*eta + ( 91.7679*pWF->chi1L*sqrt(1.-4.*eta) - 91.7679*pWF->chi2L*sqrt(1.-4.*eta))*eta2;
             total = noSpin + eqSpin + uneqSpin;
             break;
         }
@@ -2246,20 +2665,22 @@ static double IMRPhenomXHM_Inter_Phase_21_p1(double eta, double S, double chi1,
     return total;
 }
 
-static double IMRPhenomXHM_Inter_Phase_33_p1(double eta, double S, double chi1, double chi2, int InterPhaseFlag) {
-    UNUSED double total=0,eta2,eta3,eta4,eta5,eta6,eta7,S2;
+static double IMRPhenomXHM_Inter_Phase_33_p1(IMRPhenomXWaveformStruct *pWF, int InterPhaseFlag) {
+    double total=0;
     switch (InterPhaseFlag){
         case 122019:{
+            double eta = pWF->eta;
+            double S = pWF->STotR;
+            double eta2,eta3,eta4,eta5,eta6,S2;
             eta2 = pow(eta,2);
             eta3 = pow(eta,3);
             eta4 = pow(eta,4);
             eta5 = pow(eta,5);
             eta6 = pow(eta,6);
-            eta7 = pow(eta,7);
             S2 = pow(S,2);
             double noSpin = 4360.19 + 4.27128/eta - 8727.4*eta + 18485.9*eta2 + 371303.00000000006*eta3 - 3.22792e6*eta4 + 1.01799e7*eta5 - 1.15659e7*eta6;
             double eqSpin = ((11.6635 - 251.579*eta - 3255.6400000000003*eta2 + 19614.6*eta3 - 34860.2*eta4)*S + (14.8017 + 204.025*eta - 5421.92*eta2 + 36587.3*eta3 - 74299.5*eta4)*S2)/(eta);
-            double uneqSpin = eta*(223.65100000000004*chi1*sqrt(1. - 4.*eta)*(3.9201300240106223 + 1.*eta) - 223.65100000000004*chi2*sqrt(1. - 4.*eta)*(3.9201300240106223 + 1.*eta));
+            double uneqSpin = eta*(223.65100000000004*pWF->chi1L*sqrt(1.-4.*eta)*(3.9201300240106223 + 1.*eta) - 223.65100000000004*pWF->chi2L*sqrt(1.-4.*eta)*(3.9201300240106223 + 1.*eta));
             total = noSpin + eqSpin + uneqSpin;
             break;
         }
@@ -2268,22 +2689,24 @@ static double IMRPhenomXHM_Inter_Phase_33_p1(double eta, double S, double chi1,
     return total;
 }
 
-static double IMRPhenomXHM_Inter_Phase_32_p1(double eta, double S, double chi1, double chi2, int InterPhaseFlag) {
-    UNUSED double total=0,eta2,eta3,eta4,eta5,eta6,eta7,S2,S3,S4;
+static double IMRPhenomXHM_Inter_Phase_32_p1(IMRPhenomXWaveformStruct *pWF, int InterPhaseFlag) {
+    double total=0;
     switch (InterPhaseFlag){
         case 122019:{
+            double eta = pWF->eta;
+            double S = pWF->STotR;
+            double eta2,eta3,eta4,eta5,eta6,S2,S3,S4;
             eta2 = pow(eta,2);
             eta3 = pow(eta,3);
             eta4 = pow(eta,4);
             eta5 = pow(eta,5);
             eta6 = pow(eta,6);
-            eta7 = pow(eta,7);
             S2 = pow(S,2);
             S3 = pow(S,3);
             S4 = pow(S,4);
             double noSpin = 4414.11 + 4.21564/eta - 10687.8*eta + 58234.6*eta2 - 64068.40000000001*eta3 - 704442.*eta4 + 2.86393e6*eta5 - 3.26362e6*eta6;
             double eqSpin = ((6.39833 - 610.267*eta + 2095.72*eta2 - 3970.89*eta3)*S + (22.956700000000005 - 99.1551*eta + 331.593*eta2 - 794.79*eta3)*S2 + (10.4333 + 43.8812*eta - 541.261*eta2 + 294.289*eta3)*S3 + eta*(106.047 - 1569.0299999999997*eta + 4810.61*eta2)*S4)/(eta);
-            double uneqSpin = 132.244*sqrt(1. - 4.*eta)*eta*(chi1*(6.227738120444028 - 1.*eta) + chi2*(-6.227738120444028 + 1.*eta));
+            double uneqSpin = 132.244*sqrt(1.-4.*eta)*eta*(pWF->chi1L*(6.227738120444028 - 1.*eta) + pWF->chi2L*(-6.227738120444028 + 1.*eta));
             total = noSpin + eqSpin + uneqSpin;
             break;
         }
@@ -2292,21 +2715,23 @@ static double IMRPhenomXHM_Inter_Phase_32_p1(double eta, double S, double chi1,
     return total;
 }
 
-static double IMRPhenomXHM_Inter_Phase_44_p1(double eta, double S, double chi1, double chi2, int InterPhaseFlag) {
-    UNUSED double total=0,eta2,eta3,eta4,eta5,eta6, eta7,S2,S3;
+static double IMRPhenomXHM_Inter_Phase_44_p1(IMRPhenomXWaveformStruct *pWF, int InterPhaseFlag) {
+    double total=0;
     switch (InterPhaseFlag){
         case 122019:{
+            double eta = pWF->eta;
+            double S = pWF->STotR;
+            double eta2,eta3,eta4,eta5,eta6,S2,S3;
             eta2 = pow(eta,2);
             eta3 = pow(eta,3);
             eta4 = pow(eta,4);
             eta5 = pow(eta,5);
             eta6 = pow(eta,6);
-            eta7 = pow(eta,7);
             S2 = pow(S,2);
             S3 = pow(S,3);
             double noSpin = 4349.66 + 4.34125/eta - 8202.33*eta + 5534.1*eta2 + 536500.*eta3 - 4.33197e6*eta4 + 1.37792e7*eta5 - 1.60802e7*eta6;
             double eqSpin = ((12.0704 - 528.098*eta + 1822.9100000000003*eta2 - 9349.73*eta3 + 17900.9*eta4)*S + (10.4092 + 253.334*eta - 5452.04*eta2 + 35416.6*eta3 - 71523.*eta4)*S2 + eta*(492.60300000000007 - 9508.5*eta + 57303.4*eta2 - 109418.*eta3)*S3)/(eta);
-            double uneqSpin = -262.143*sqrt(1. - 4.*eta)*eta*(chi1*(-3.0782778864970646 - 1.*eta) + chi2*(3.0782778864970646 + 1.*eta));
+            double uneqSpin = -262.143*sqrt(1.-4.*eta)*eta*(pWF->chi1L*(-3.0782778864970646 - 1.*eta) + pWF->chi2L*(3.0782778864970646 + 1.*eta));
             total = noSpin + eqSpin + uneqSpin;
             break;
         }
@@ -2316,22 +2741,24 @@ static double IMRPhenomXHM_Inter_Phase_44_p1(double eta, double S, double chi1,
 }
 
 
-static double IMRPhenomXHM_Inter_Phase_21_p2(double eta, double S, double chi1, double chi2, int InterPhaseFlag) {
-    UNUSED double total=0,eta2,eta3,eta4,eta5,eta6,eta7,S2,S3,S4;
+static double IMRPhenomXHM_Inter_Phase_21_p2(IMRPhenomXWaveformStruct *pWF, int InterPhaseFlag) {
+    double total=0;
     switch (InterPhaseFlag){
         case 122019:{
+            double eta = pWF->eta;
+            double S = pWF->STotR;
+            double eta2,eta3,eta4,eta5,eta6,S2,S3,S4;
             eta2 = pow(eta,2);
             eta3 = eta2*eta;
             eta4 = eta3*eta;
             eta5 = eta3*eta2;
             eta6 = eta4*eta2;
-            eta7 = eta4*eta3;
             S2 = pow(S,2);
             S3 = pow(S,3);
             S4= S3*S;
             double noSpin = 3509.09 + 0.91868/eta + 194.72*eta - 27556.2*eta2 + 369153.*eta3 - 2.28832e6*eta4 + 6.82533e6*eta5 - 7.86254e6*eta6;
             double eqSpin = ((0.7083999999999999 - 60.1611*eta + 131.815*eta2 - 619.837*eta3)*S + (6.104720000000001 - 59.2068*eta + 278.588*eta2 - 722.787*eta3)*S2 + (5.7791 + 117.913*eta - 1180.4*eta2 + 2392.73*eta3)*S3 + eta*(92.6654 - 1077.75*eta + 2689.18*eta2)*S4)/(eta);
-            double uneqSpin = -91.7679*sqrt(1. - 4.*eta)*eta*(chi1*(-1.6012352903357276 - 1.*eta) + chi2*(1.6012352903357276 + 1.*eta));
+            double uneqSpin = -91.7679*sqrt(1.-4.*eta)*eta*(pWF->chi1L*(-1.6012352903357276 - 1.*eta) + pWF->chi2L*(1.6012352903357276 + 1.*eta));
             total = noSpin + eqSpin + uneqSpin;
             break;
         }
@@ -2340,20 +2767,22 @@ static double IMRPhenomXHM_Inter_Phase_21_p2(double eta, double S, double chi1,
     return total;
 }
 
-static double IMRPhenomXHM_Inter_Phase_33_p2(double eta, double S, double chi1, double chi2, int InterPhaseFlag) {
-    UNUSED double total=0,eta2,eta3,eta4,eta5,eta6,eta7,S2;
+static double IMRPhenomXHM_Inter_Phase_33_p2(IMRPhenomXWaveformStruct *pWF, int InterPhaseFlag) {
+    double total=0;
     switch (InterPhaseFlag){
         case 122019:{
+            double eta = pWF->eta;
+            double S = pWF->STotR;
+            double eta2,eta3,eta4,eta5,eta6,S2;
             eta2 = pow(eta,2);
             eta3 = pow(eta,3);
             eta4 = pow(eta,4);
             eta5 = pow(eta,5);
             eta6 = pow(eta,6);
-            eta7 = pow(eta,7);
             S2 = pow(S,2);
             double noSpin = 3797.06 + 0.786684/eta - 2397.09*eta - 25514.*eta2 + 518314.99999999994*eta3 - 3.41708e6*eta4 + 1.01799e7*eta5 - 1.15659e7*eta6;
             double eqSpin = ((6.7812399999999995 + 39.4668*eta - 3520.37*eta2 + 19614.6*eta3 - 34860.2*eta4)*S + (4.80384 + 293.215*eta - 5914.61*eta2 + 36587.3*eta3 - 74299.5*eta4)*S2)/(eta);
-            double uneqSpin = -223.65100000000004*sqrt(1. - 4.*eta)*eta*(chi1*(-1.3095134830606614 - 1.*eta) + chi2*(1.3095134830606614 + 1.*eta));
+            double uneqSpin = -223.65100000000004*sqrt(1.-4.*eta)*eta*(pWF->chi1L*(-1.3095134830606614 - 1.*eta) + pWF->chi2L*(1.3095134830606614 + 1.*eta));
             total = noSpin + eqSpin + uneqSpin;
             break;
         }
@@ -2362,22 +2791,24 @@ static double IMRPhenomXHM_Inter_Phase_33_p2(double eta, double S, double chi1,
     return total;
 }
 
-static double IMRPhenomXHM_Inter_Phase_32_p2(double eta, double S, double chi1, double chi2, int InterPhaseFlag) {
-    UNUSED double total=0,eta2,eta3,eta4,eta5,eta6,eta7,S2,S3,S4;
+static double IMRPhenomXHM_Inter_Phase_32_p2(IMRPhenomXWaveformStruct *pWF, int InterPhaseFlag) {
+    double total=0;
     switch (InterPhaseFlag){
         case 122019:{
+            double eta = pWF->eta;
+            double S = pWF->STotR;
+            double eta2,eta3,eta4,eta5,eta6,S2,S3,S4;
             eta2 = pow(eta,2);
             eta3 = pow(eta,3);
             eta4 = pow(eta,4);
             eta5 = pow(eta,5);
             eta6 = pow(eta,6);
-            eta7 = pow(eta,7);
             S2 = pow(S,2);
             S3 = pow(S,3);
             S4 = pow(S,4);
             double noSpin = 3980.7 + 0.956703/eta - 6202.38*eta + 29218.1*eta2 + 24484.2*eta3 - 807629.*eta4 + 2.86393e6*eta5 - 3.26362e6*eta6;
             double eqSpin = ((1.92692 - 226.825*eta + 75.246*eta2 + 1291.56*eta3)*S + (15.328700000000001 - 99.1551*eta + 608.328*eta2 - 2402.94*eta3)*S2 + (10.4333 + 43.8812*eta - 541.261*eta2 + 294.289*eta3)*S3 + eta*(106.047 - 1569.0299999999997*eta + 4810.61*eta2)*S4)/(eta);
-            double uneqSpin = 132.244*sqrt(1. - 4.*eta)*eta*(chi1*(2.5769789177580837 - 1.*eta) + chi2*(-2.5769789177580837 + 1.*eta));
+            double uneqSpin = 132.244*sqrt(1.-4.*eta)*eta*(pWF->chi1L*(2.5769789177580837 - 1.*eta) + pWF->chi2L*(-2.5769789177580837 + 1.*eta));
             total = noSpin + eqSpin + uneqSpin;
             break;
         }
@@ -2386,21 +2817,23 @@ static double IMRPhenomXHM_Inter_Phase_32_p2(double eta, double S, double chi1,
     return total;
 }
 
-static double IMRPhenomXHM_Inter_Phase_44_p2(double eta, double S, double chi1, double chi2, int InterPhaseFlag) {
-    UNUSED double total=0,eta2,eta3,eta4,eta5,eta6,eta7,S2,S3;
+static double IMRPhenomXHM_Inter_Phase_44_p2(IMRPhenomXWaveformStruct *pWF, int InterPhaseFlag) {
+    double total=0;
     switch (InterPhaseFlag){
         case 122019:{
+            double eta = pWF->eta;
+            double S = pWF->STotR;
+            double eta2,eta3,eta4,eta5,eta6,S2,S3;
             eta2 = pow(eta,2);
             eta3 = pow(eta,3);
             eta4 = pow(eta,4);
             eta5 = pow(eta,5);
             eta6 = pow(eta,6);
-            eta7 = pow(eta,7);
             S2 = pow(S,2);
             S3 = pow(S,3);
             double noSpin = 3804.19 + 0.66144/eta - 2421.77*eta - 33475.8*eta2 + 665951.*eta3 - 4.50145e6*eta4 + 1.37792e7*eta5 - 1.60802e7*eta6;
             double eqSpin = ((5.83038 - 172.047*eta + 926.576*eta2 - 7676.87*eta3 + 17900.9*eta4)*S + (6.17601 + 253.334*eta - 5672.02*eta2 + 35722.1*eta3 - 71523.*eta4)*S2 + eta*(492.60300000000007 - 9508.5*eta + 57303.4*eta2 - 109418.*eta3)*S3)/(eta);
-            double uneqSpin = -262.143*sqrt(1. - 4.*eta)*eta*(chi1*(-1.0543062374352932 - 1.*eta) + chi2*(1.0543062374352932 + 1.*eta));
+            double uneqSpin = -262.143*sqrt(1.-4.*eta)*eta*(pWF->chi1L*(-1.0543062374352932 - 1.*eta) + pWF->chi2L*(1.0543062374352932 + 1.*eta));
             total = noSpin + eqSpin + uneqSpin;
             break;
         }
@@ -2410,23 +2843,25 @@ static double IMRPhenomXHM_Inter_Phase_44_p2(double eta, double S, double chi1,
 }
 
 
-static double IMRPhenomXHM_Inter_Phase_21_p3(double eta, double S, double chi1, double chi2, int InterPhaseFlag) {
-    UNUSED double total=0,eta2,eta3,eta4,eta5,eta6,eta7,S2,S3,S4;
-    double delta=sqrt(1.-4*eta);
+static double IMRPhenomXHM_Inter_Phase_21_p3(IMRPhenomXWaveformStruct *pWF, int InterPhaseFlag) {
+    double total=0;
     switch (InterPhaseFlag){
         case 122019:{
+            double eta = pWF->eta;
+            double S = pWF->STotR;
+            double delta=sqrt(1.-4.*eta);
+            double eta2,eta3,eta4,eta5,eta6,S2,S3,S4;
             eta2 = pow(eta,2);
             eta3 = eta2*eta;
             eta4 = eta2*eta2;
             eta5 = eta2*eta3;
             eta6 = eta3*eta3;
-            eta7 = eta3*eta4;
             S2 = pow(S,2);
             S3 = pow(S,3);
             S4 = pow(S,4);
             double noSpin = 3241.68 + 890.016*eta - 28651.9*eta2 + 369153.*eta3 - 2.28832e6*eta4 + 6.82533e6*eta5 - 7.86254e6*eta6;
             double eqSpin = (-2.2484 + 187.641*eta - 619.837*eta2)*S + (3.22603 + 166.323*eta - 722.787*eta2)*S2 + (117.913 - 1094.59*eta + 2392.73*eta2)*S3 + (92.6654 - 1077.75*eta + 2689.18*eta2)*S4;
-            double uneqSpin = 91.7679*(chi1 - 1.*chi2)*delta*eta2;
+            double uneqSpin = 91.7679*(pWF->dchi)*delta*eta2;
             total = noSpin + eqSpin + uneqSpin;
             break;
         }
@@ -2435,10 +2870,13 @@ static double IMRPhenomXHM_Inter_Phase_21_p3(double eta, double S, double chi1,
     return total;
 }
 
-static double IMRPhenomXHM_Inter_Phase_33_p3(double eta, double S, double chi1, double chi2, int InterPhaseFlag) {
-    UNUSED double total=0,eta2,eta3,eta4,eta5,eta6,S2;
+static double IMRPhenomXHM_Inter_Phase_33_p3(IMRPhenomXWaveformStruct *pWF, int InterPhaseFlag) {
+    double total=0;
     switch (InterPhaseFlag){
         case 122019:{
+            double eta = pWF->eta;
+            double S = pWF->STotR;
+            double eta2,eta3,eta4,eta5,eta6,S2;
             eta2 = pow(eta,2);
             eta3 = pow(eta,3);
             eta4 = pow(eta,4);
@@ -2447,7 +2885,7 @@ static double IMRPhenomXHM_Inter_Phase_33_p3(double eta, double S, double chi1,
             S2 = pow(S,2);
             double noSpin = 3321.83 + 1796.03*eta - 52406.1*eta2 + 605028.*eta3 - 3.52532e6*eta4 + 1.01799e7*eta5 - 1.15659e7*eta6;
             double eqSpin = (223.601 - 3714.77*eta + 19614.6*eta2 - 34860.2*eta3)*S + (314.317 - 5906.46*eta + 36587.3*eta2 - 74299.5*eta3)*S2;
-            double uneqSpin = 223.651*(chi1 - 1.*chi2)*sqrt(1. - 4.*eta)*eta2;
+            double uneqSpin = 223.651*(pWF->dchi)*sqrt(1.-4.*eta)*eta2;
             total = noSpin + eqSpin + uneqSpin;
             break;
         }
@@ -2456,10 +2894,13 @@ static double IMRPhenomXHM_Inter_Phase_33_p3(double eta, double S, double chi1,
     return total;
 }
 
-static double IMRPhenomXHM_Inter_Phase_32_p3(double eta, double S, double chi1, double chi2, int InterPhaseFlag) {
-    UNUSED double total=0,eta2,eta3,eta4,eta5,eta6,S2,S3,S4;
+static double IMRPhenomXHM_Inter_Phase_32_p3(IMRPhenomXWaveformStruct *pWF, int InterPhaseFlag) {
+    double total=0;
     switch (InterPhaseFlag){
         case 122019:{
+            double eta = pWF->eta;
+            double S = pWF->STotR;
+            double eta2,eta3,eta4,eta5,eta6,S2,S3,S4;
             eta2 = pow(eta,2);
             eta3 = pow(eta,3);
             eta4 = pow(eta,4);
@@ -2470,7 +2911,7 @@ static double IMRPhenomXHM_Inter_Phase_32_p3(double eta, double S, double chi1,
             S4 = pow(S,4);
             double noSpin = 3416.57 + 2308.63*eta - 84042.9*eta2 + 1.01936e6*eta3 - 6.0644e6*eta4 + 1.76399e7*eta5 - 2.0065e7*eta6;
             double eqSpin = (24.6295 - 282.354*eta - 2582.55*eta2 + 12750.*eta3)*S + (433.675 - 8775.86*eta + 56407.8*eta2 - 114798.*eta3)*S2 + (559.705 - 10627.4*eta + 61581.*eta2 - 114029.*eta3)*S3 + (106.047 - 1569.03*eta + 4810.61*eta2)*S4;
-            double uneqSpin = 63.9466*(1.*chi1 - 1.*chi2)*sqrt(1. - 4.*eta)*eta2;
+            double uneqSpin = 63.9466*pWF->dchi*sqrt(1.-4.*eta)*eta2;
             total = noSpin + eqSpin + uneqSpin;
             break;
         }
@@ -2479,10 +2920,13 @@ static double IMRPhenomXHM_Inter_Phase_32_p3(double eta, double S, double chi1,
     return total;
 }
 
-static double IMRPhenomXHM_Inter_Phase_44_p3(double eta, double S, double chi1, double chi2, int InterPhaseFlag) {
-    UNUSED double total=0,eta2,eta3,eta4, eta5, eta6, S2, S3;
+static double IMRPhenomXHM_Inter_Phase_44_p3(IMRPhenomXWaveformStruct *pWF, int InterPhaseFlag) {
+    double total=0;
     switch (InterPhaseFlag){
         case 122019:{
+            double eta = pWF->eta;
+            double S = pWF->STotR;
+            double eta2,eta3,eta4, eta5, eta6, S2, S3;
             eta2 = pow(eta,2);
             eta3 = pow(eta,3);
             eta4 = pow(eta,4);
@@ -2492,7 +2936,7 @@ static double IMRPhenomXHM_Inter_Phase_44_p3(double eta, double S, double chi1,
             S3 = pow(S,3);
             double noSpin = 3308.97 + 2353.58*eta - 66340.1*eta2 + 777272.*eta3 - 4.64438e6*eta4 + 1.37792e7*eta5 - 1.60802e7*eta6;
             double eqSpin = (-21.5697 + 926.576*eta - 7989.26*eta2 + 17900.9*eta3)*S + (353.539 - 6403.24*eta + 37599.5*eta2 - 71523.*eta3)*S2 + (492.603 - 9508.5*eta + 57303.4*eta2 - 109418.*eta3)*S3;
-            double uneqSpin = 262.143*(chi1 - 1.*chi2)*sqrt(1. - 4.*eta)*eta2;
+            double uneqSpin = 262.143*(pWF->dchi)*sqrt(1.-4.*eta)*eta2;
             total = noSpin + eqSpin + uneqSpin;
             break;
         }
@@ -2502,11 +2946,13 @@ static double IMRPhenomXHM_Inter_Phase_44_p3(double eta, double S, double chi1,
 }
 
 
-static double IMRPhenomXHM_Inter_Phase_21_p4(double eta, double S, double chi1, double chi2, int InterPhaseFlag) {
-    UNUSED double total=0,eta2,eta3,eta4,eta5,eta6,S2,S3,S4;
-    //double delta=sqrt(1.-4.*eta);
+static double IMRPhenomXHM_Inter_Phase_21_p4(IMRPhenomXWaveformStruct *pWF, int InterPhaseFlag) {
+    double total=0;
     switch (InterPhaseFlag){
         case 122019:{
+            double eta = pWF->eta;
+            double S = pWF->STotR;
+            double eta2,eta3,eta4,eta5,eta6,S2,S3,S4;
             eta2 = pow(eta,2);
             eta3 = pow(eta,3);
             eta4 = pow(eta,4);
@@ -2517,7 +2963,7 @@ static double IMRPhenomXHM_Inter_Phase_21_p4(double eta, double S, double chi1,
             S4 = pow(S,4);
             double noSpin = 3160.88 + 974.355*eta - 28932.5*eta2 + 369780.*eta3 - 2.28832e6*eta4 + 6.82533e6*eta5 - 7.86254e6*eta6;
             double eqSpin = (26.3355 - 196.851*eta + 438.401*eta2)*S + (45.9957 - 256.248*eta + 117.563*eta2)*S2 + (-20.0261 + 467.057*eta - 1613.*eta2)*S3 + (-61.7446 + 577.057*eta - 1096.81*eta2)*S4;
-            double uneqSpin = 65.3326*(1.*chi1 - 1.*chi2)*sqrt(1. - 4.*eta)*eta2;
+            double uneqSpin = 65.3326*pWF->dchi*sqrt(1.-4.*eta)*eta2;
             total = noSpin + eqSpin + uneqSpin;
             break;
         }
@@ -2526,10 +2972,13 @@ static double IMRPhenomXHM_Inter_Phase_21_p4(double eta, double S, double chi1,
     return total;
 }
 
-static double IMRPhenomXHM_Inter_Phase_33_p4(double eta, double S, double chi1, double chi2, int InterPhaseFlag) {
-    UNUSED double total=0,eta2,eta3,eta4,eta5, eta6,S2,S3;
+static double IMRPhenomXHM_Inter_Phase_33_p4(IMRPhenomXWaveformStruct *pWF, int InterPhaseFlag) {
+    double total=0;
     switch (InterPhaseFlag){
         case 122019:{
+            double eta = pWF->eta;
+            double S = pWF->STotR;
+            double eta2,eta3,eta4,eta5, eta6,S2,S3;
             eta2 = pow(eta,2);
             eta3 = pow(eta,3);
             eta4 = pow(eta,4);
@@ -2539,7 +2988,7 @@ static double IMRPhenomXHM_Inter_Phase_33_p4(double eta, double S, double chi1,
             S3 = pow(S,3);
             double noSpin = 3239.44 - 661.15*eta + 5139.79*eta2 + 3456.2*eta3 - 248477.*eta4 + 1.17255e6*eta5 - 1.70363e6*eta6;
             double eqSpin = (225.859 - 4150.09*eta + 24364.*eta2 - 46537.3*eta3)*S + (35.2439 - 994.971*eta + 8953.98*eta2 - 23603.5*eta3)*S2 + (-310.489 + 5946.15*eta - 35337.1*eta2 + 67102.4*eta3)*S3;
-            double uneqSpin = 30.484*(1.*chi1 - 1.*chi2)*sqrt(1. - 4.*eta)*eta2;
+            double uneqSpin = 30.484*pWF->dchi*sqrt(1.-4.*eta)*eta2;
             total = noSpin + eqSpin + uneqSpin;
             break;
         }
@@ -2548,10 +2997,13 @@ static double IMRPhenomXHM_Inter_Phase_33_p4(double eta, double S, double chi1,
     return total;
 }
 
-static double IMRPhenomXHM_Inter_Phase_32_p4(double eta, double S, double chi1, double chi2, int InterPhaseFlag) {
-    UNUSED double total=0,eta2,eta3,eta4,eta5,eta6,S2,S3,S4;
+static double IMRPhenomXHM_Inter_Phase_32_p4(IMRPhenomXWaveformStruct *pWF, int InterPhaseFlag) {
+    double total=0;
     switch (InterPhaseFlag){
         case 122019:{
+            double eta = pWF->eta;
+            double S = pWF->STotR;
+            double eta2,eta3,eta4,eta5,eta6,S2,S3,S4;
             eta2 = pow(eta,2);
             eta3 = pow(eta,3);
             eta4 = pow(eta,4);
@@ -2562,7 +3014,7 @@ static double IMRPhenomXHM_Inter_Phase_32_p4(double eta, double S, double chi1,
             S4 = pow(S,4);
             double noSpin = 3307.49 - 476.909*eta - 5980.37*eta2 + 127610.*eta3 - 919108.*eta4 + 2.86393e6*eta5 - 3.26362e6*eta6;
             double eqSpin = (-5.02553 - 282.354*eta + 1291.56*eta2)*S + (-43.8823 + 740.123*eta - 2402.94*eta2)*S2 + (43.8812 - 370.362*eta + 294.289*eta2)*S3 + (106.047 - 1569.03*eta + 4810.61*eta2)*S4;
-            double uneqSpin = -132.244*(chi1 - 1.*chi2)*sqrt(1. - 4.*eta)*eta2;
+            double uneqSpin = -132.244*(pWF->dchi)*sqrt(1.-4.*eta)*eta2;
             total = noSpin + eqSpin + uneqSpin;
             break;
         }
@@ -2571,10 +3023,13 @@ static double IMRPhenomXHM_Inter_Phase_32_p4(double eta, double S, double chi1,
     return total;
 }
 
-static double IMRPhenomXHM_Inter_Phase_44_p4(double eta, double S, double chi1, double chi2, int InterPhaseFlag) {
-    UNUSED double total=0,eta2,eta3,eta4,eta5,eta6,S2,S3;
+static double IMRPhenomXHM_Inter_Phase_44_p4(IMRPhenomXWaveformStruct *pWF, int InterPhaseFlag) {
+    double total=0;
     switch (InterPhaseFlag){
         case 122019:{
+            double eta = pWF->eta;
+            double S = pWF->STotR;
+            double eta2,eta3,eta4,eta5,eta6,S2,S3;
             eta2 = pow(eta,2);
             eta3 = pow(eta,3);
             eta4 = pow(eta,4);
@@ -2584,7 +3039,7 @@ static double IMRPhenomXHM_Inter_Phase_44_p4(double eta, double S, double chi1,
             S3 = pow(S,3);
             double noSpin = 3245.63 - 928.56*eta + 8463.89*eta2 - 17422.6*eta3 - 165169.*eta4 + 908279.*eta5 - 1.31138e6*eta6;
             double eqSpin = (32.506 - 590.293*eta + 3536.61*eta2 - 6758.52*eta3)*S + (-25.7716 + 738.141*eta - 4867.87*eta2 + 9129.45*eta3)*S2 + (-15.7439 + 620.695*eta - 4679.24*eta2 + 9582.58*eta3)*S3;
-            double uneqSpin = 87.0832*(1.*chi1 - 1.*chi2)*sqrt(1. - 4.*eta)*eta2;
+            double uneqSpin = 87.0832*pWF->dchi*sqrt(1.-4.*eta)*eta2;
             total = noSpin + eqSpin + uneqSpin;
             break;
         }
@@ -2594,10 +3049,13 @@ static double IMRPhenomXHM_Inter_Phase_44_p4(double eta, double S, double chi1,
 }
 
 
-static double IMRPhenomXHM_Inter_Phase_21_p5(double eta, double S, double chi1, double chi2, int InterPhaseFlag) {
-    UNUSED double total=0, delta=sqrt(1.- 4.*eta),eta2,eta3,S2,S3,S4;
+static double IMRPhenomXHM_Inter_Phase_21_p5(IMRPhenomXWaveformStruct *pWF, int InterPhaseFlag) {
+    double total=0;
     switch (InterPhaseFlag){
         case 122019:{
+            double eta = pWF->eta;
+            double S = pWF->STotR;
+            double eta2,eta3,S2,S3,S4;
             eta2 = pow(eta,2);
             eta3 = pow(eta,3);
             S2 = pow(S,2);
@@ -2605,7 +3063,7 @@ static double IMRPhenomXHM_Inter_Phase_21_p5(double eta, double S, double chi1,
             S4 = pow(S,4);
             double noSpin = 3102.36 + 315.911*eta - 1688.26*eta2 + 3635.76*eta3;
             double eqSpin = (-23.0959 + 320.93*eta - 1029.76*eta2)*S + (-49.5435 + 826.816*eta - 3079.39*eta2)*S2 + (40.7054 - 365.842*eta + 1094.11*eta2)*S3 + (81.8379 - 1243.26*eta + 4689.22*eta2)*S4;
-            double uneqSpin = 119.014*(chi1 - 1.*chi2)*sqrt(1. - 4.*eta)*eta2;
+            double uneqSpin = 119.014*(pWF->dchi)*sqrt(1.-4.*eta)*eta2;
             total = noSpin + eqSpin + uneqSpin;
             break;
         }
@@ -2614,10 +3072,13 @@ static double IMRPhenomXHM_Inter_Phase_21_p5(double eta, double S, double chi1,
     return total;
 }
 
-static double IMRPhenomXHM_Inter_Phase_33_p5(double eta, double S, double chi1, double chi2, int InterPhaseFlag) {
-    UNUSED double total=0,eta2,eta3,eta4,eta5,eta6,S2,S3;
+static double IMRPhenomXHM_Inter_Phase_33_p5(IMRPhenomXWaveformStruct *pWF, int InterPhaseFlag) {
+    double total=0;
     switch (InterPhaseFlag){
         case 122019:{
+            double eta = pWF->eta;
+            double S = pWF->STotR;
+            double eta2,eta3,eta4,eta5,eta6,S2,S3;
             eta2 = pow(eta,2);
             eta3 = pow(eta,3);
             eta4 = pow(eta,4);
@@ -2627,7 +3088,7 @@ static double IMRPhenomXHM_Inter_Phase_33_p5(double eta, double S, double chi1,
             S3 = pow(S,3);
             double noSpin = 3114.3 + 2143.06*eta - 49428.3*eta2 + 563997.*eta3 - 3.35991e6*eta4 + 9.99745e6*eta5 - 1.17123e7*eta6;
             double eqSpin = (190.051 - 3705.08*eta + 23046.2*eta2 - 46537.3*eta3)*S + (63.6615 - 1414.2*eta + 10166.1*eta2 - 23603.5*eta3)*S2 + (-257.524 + 5179.97*eta - 33001.4*eta2 + 67102.4*eta3)*S3;
-            double uneqSpin = 54.9833*(1.*chi1 - 1.*chi2)*sqrt(1. - 4.*eta)*eta2;
+            double uneqSpin = 54.9833*pWF->dchi*sqrt(1.-4.*eta)*eta2;
             total = noSpin + eqSpin + uneqSpin;
             break;
         }
@@ -2636,10 +3097,13 @@ static double IMRPhenomXHM_Inter_Phase_33_p5(double eta, double S, double chi1,
     return total;
 }
 
-static double IMRPhenomXHM_Inter_Phase_32_p5(double eta, double S, double chi1, double chi2, int InterPhaseFlag) {
-    UNUSED double total=0,eta2,eta3,eta4,eta5,eta6,eta7,S2,S3,S4;
+static double IMRPhenomXHM_Inter_Phase_32_p5(IMRPhenomXWaveformStruct *pWF, int InterPhaseFlag) {
+    double total=0;
     switch (InterPhaseFlag){
         case 122019:{
+            double eta = pWF->eta;
+            double S = pWF->STotR;
+            double eta2,eta3,eta4,eta5,eta6,eta7,S2,S3,S4;
             eta2 = pow(eta,2);
             eta3 = pow(eta,3);
             eta4 = pow(eta,4);
@@ -2651,7 +3115,7 @@ static double IMRPhenomXHM_Inter_Phase_32_p5(double eta, double S, double chi1,
             S4 = pow(S,4);
             double noSpin = 3259.03 - 3967.58*eta + 111203.*eta2 - 1.81883e6*eta3 + 1.73811e7*eta4 - 9.56988e7*eta5 + 2.75056e8*eta6 - 3.15866e8*eta7;
             double eqSpin = (19.7509 - 1104.53*eta + 3810.18*eta2)*S + (-230.07 + 2314.51*eta - 5944.49*eta2)*S2 + (-201.633 + 2183.43*eta - 6233.99*eta2)*S3 + (106.047 - 1569.03*eta + 4810.61*eta2)*S4;
-            double uneqSpin = 112.714*(1.*chi1 - 1.*chi2)*sqrt(1. - 4.*eta)*eta2;
+            double uneqSpin = 112.714*pWF->dchi*sqrt(1.-4.*eta)*eta2;
             total = noSpin + eqSpin + uneqSpin;
             break;
         }
@@ -2660,10 +3124,13 @@ static double IMRPhenomXHM_Inter_Phase_32_p5(double eta, double S, double chi1,
     return total;
 }
 
-static double IMRPhenomXHM_Inter_Phase_44_p5(double eta, double S, double chi1, double chi2, int InterPhaseFlag) {
-    UNUSED double total=0,eta2,eta3,eta4,eta5,eta6,eta7,S2,S3;
+static double IMRPhenomXHM_Inter_Phase_44_p5(IMRPhenomXWaveformStruct *pWF, int InterPhaseFlag) {
+    double total=0;
     switch (InterPhaseFlag){
         case 122019:{
+            double eta = pWF->eta;
+            double S = pWF->STotR;
+            double eta2,eta3,eta4,eta5,eta6,eta7,S2,S3;
             eta2 = pow(eta,2);
             eta3 = pow(eta,3);
             eta4 = pow(eta,4);
@@ -2674,7 +3141,7 @@ static double IMRPhenomXHM_Inter_Phase_44_p5(double eta, double S, double chi1,
             S3 = pow(S,3);
             double noSpin = 3108.38 + 3722.46*eta - 119588.*eta2 + 1.92148e6*eta3 - 1.69796e7*eta4 + 8.39194e7*eta5 - 2.17143e8*eta6 + 2.2829700000000003e8*eta7;
             double eqSpin = (118.319 - 529.854*eta)*eta*S + (21.0314 - 240.648*eta + 516.333*eta2)*S2 + (20.3384 - 356.241*eta + 999.417*eta2)*S3;
-            double uneqSpin = 97.1364*(chi1 - 1.*chi2)*sqrt(1. - 4.*eta)*eta2;
+            double uneqSpin = 97.1364*(pWF->dchi)*sqrt(1.-4.*eta)*eta2;
             total = noSpin + eqSpin + uneqSpin;
             break;
         }
@@ -2684,10 +3151,13 @@ static double IMRPhenomXHM_Inter_Phase_44_p5(double eta, double S, double chi1,
 }
 
 
-static double IMRPhenomXHM_Inter_Phase_21_p6(double eta, double S, double chi1, double chi2, int InterPhaseFlag) {
-    UNUSED double total=0,eta2,eta3,S2,S3,S4;
+static double IMRPhenomXHM_Inter_Phase_21_p6(IMRPhenomXWaveformStruct *pWF, int InterPhaseFlag) {
+    double total=0;
     switch (InterPhaseFlag){
         case 122019:{
+            double eta = pWF->eta;
+            double S = pWF->STotR;
+            double eta2,eta3,S2,S3,S4;
             eta2 = pow(eta,2);
             eta3 = pow(eta,3);
             S2 = pow(S,2);
@@ -2695,7 +3165,7 @@ static double IMRPhenomXHM_Inter_Phase_21_p6(double eta, double S, double chi1,
             S4 = pow(S,4);
             double noSpin = 3089.18 + 4.89194*eta + 190.008*eta2 - 255.245*eta3;
             double eqSpin = (2.96997 + 57.1612*eta - 432.223*eta2)*S + (-18.8929 + 630.516*eta - 2804.66*eta2)*S2 + (-24.6193 + 549.085*eta2)*S3 + (-12.8798 - 722.674*eta + 3967.43*eta2)*S4;
-            double uneqSpin = 74.0984*(chi1 - 1.*chi2)*sqrt(1. - 4.*eta)*eta2;
+            double uneqSpin = 74.0984*(pWF->dchi)*sqrt(1.-4.*eta)*eta2;
             total = noSpin + eqSpin + uneqSpin;
             break;
         }
@@ -2704,10 +3174,13 @@ static double IMRPhenomXHM_Inter_Phase_21_p6(double eta, double S, double chi1,
     return total;
 }
 
-static double IMRPhenomXHM_Inter_Phase_33_p6(double eta, double S, double chi1, double chi2, int InterPhaseFlag) {
-    UNUSED double total=0,eta2,eta3, eta4, eta5, eta6,S2,S3;
+static double IMRPhenomXHM_Inter_Phase_33_p6(IMRPhenomXWaveformStruct *pWF, int InterPhaseFlag) {
+    double total=0;
     switch (InterPhaseFlag){
         case 122019:{
+            double eta = pWF->eta;
+            double S = pWF->STotR;
+            double eta2,eta3, eta4, eta5, eta6,S2,S3;
             eta2 = pow(eta,2);
             eta3 = pow(eta,3);
             eta4 = pow(eta,4);
@@ -2717,7 +3190,7 @@ static double IMRPhenomXHM_Inter_Phase_33_p6(double eta, double S, double chi1,
             S3 = pow(S,3);
             double noSpin = 3111.46 + 384.121*eta - 13003.6*eta2 + 179537.*eta3 - 1.19313e6*eta4 + 3.79886e6*eta5 - 4.64858e6*eta6;
             double eqSpin = (182.864 - 3834.22*eta + 24532.9*eta2 - 50165.9*eta3)*S + (21.0158 - 746.957*eta + 6701.33*eta2 - 17842.3*eta3)*S2 + (-292.855 + 5886.62*eta - 37382.4*eta2 + 75501.8*eta3)*S3;
-            double uneqSpin = 75.5162*(1.*chi1 - 1.*chi2)*sqrt(1. - 4.*eta)*eta2;
+            double uneqSpin = 75.5162*pWF->dchi*sqrt(1.-4.*eta)*eta2;
             total = noSpin + eqSpin + uneqSpin;
             break;
         }
@@ -2726,10 +3199,13 @@ static double IMRPhenomXHM_Inter_Phase_33_p6(double eta, double S, double chi1,
     return total;
 }
 
-static double IMRPhenomXHM_Inter_Phase_32_p6(double eta, double S, double chi1, double chi2, int InterPhaseFlag) {
-    UNUSED double total=0,eta2,eta3,eta4,eta5,eta6,eta7,S2,S3,S4;
+static double IMRPhenomXHM_Inter_Phase_32_p6(IMRPhenomXWaveformStruct *pWF, int InterPhaseFlag) {
+    double total=0;
     switch (InterPhaseFlag){
         case 122019:{
+            double eta = pWF->eta;
+            double S = pWF->STotR;
+            double eta2,eta3,eta4,eta5,eta6,eta7,S2,S3,S4;
             eta2 = pow(eta,2);
             eta3 = pow(eta,3);
             eta4 = pow(eta,4);
@@ -2741,7 +3217,7 @@ static double IMRPhenomXHM_Inter_Phase_32_p6(double eta, double S, double chi1,
             S4 = pow(S,4);
             double noSpin = 3259.03 - 3967.58*eta + 111203.*eta2 - 1.81883e6*eta3 + 1.73811e7*eta4 - 9.56988e7*eta5 + 2.75056e8*eta6 - 3.15866e8*eta7;
             double eqSpin = (19.7509 - 1104.53*eta + 3810.18*eta2)*S + (-230.07 + 2314.51*eta - 5944.49*eta2)*S2 + (-201.633 + 2183.43*eta - 6233.99*eta2)*S3 + (106.047 - 1569.03*eta + 4810.61*eta2)*S4;
-            double uneqSpin = 112.714*(1.*chi1 - 1.*chi2)*sqrt(1. - 4.*eta)*eta2;
+            double uneqSpin = 112.714*pWF->dchi*sqrt(1.-4.*eta)*eta2;
             total = noSpin + eqSpin + uneqSpin;
             break;
         }
@@ -2750,10 +3226,13 @@ static double IMRPhenomXHM_Inter_Phase_32_p6(double eta, double S, double chi1,
     return total;
 }
 
-static double IMRPhenomXHM_Inter_Phase_44_p6(double eta, double S, double chi1, double chi2, int InterPhaseFlag) {
-    UNUSED double total=0.,eta2,eta3,eta4,eta5,eta6,S2,S3;
+static double IMRPhenomXHM_Inter_Phase_44_p6(IMRPhenomXWaveformStruct *pWF, int InterPhaseFlag) {
+    double total=0.;
     switch (InterPhaseFlag){
         case 122019:{
+            double eta = pWF->eta;
+            double S = pWF->STotR;
+            double eta2,eta3,eta4,eta5,eta6,S2,S3;
             eta2 = pow(eta,2);
             eta3 = pow(eta,3);
             eta4 = pow(eta,4);
@@ -2763,7 +3242,7 @@ static double IMRPhenomXHM_Inter_Phase_44_p6(double eta, double S, double chi1,
             S3 = pow(S,3);
             double noSpin = 3096.03 + 986.752*eta - 20371.1*eta2 + 220332.*eta3 - 1.31523e6*eta4 + 4.29193e6*eta5 - 6.01179e6*eta6;
             double eqSpin = (-9.96292 - 118.526*eta + 2255.76*eta2 - 6758.52*eta3)*S + (-14.4869 + 370.039*eta - 3605.8*eta2 + 9129.45*eta3)*S2 + (17.0209 + 70.1931*eta - 3070.08*eta2 + 9582.58*eta3)*S3;
-            double uneqSpin = 23.0759*(1.*chi1 - 1.*chi2)*sqrt(1. - 4.*eta)*eta2;
+            double uneqSpin = 23.0759*pWF->dchi*sqrt(1.-4.*eta)*eta2;
             total = noSpin + eqSpin + uneqSpin;
             break;
         }
@@ -2772,7 +3251,7 @@ static double IMRPhenomXHM_Inter_Phase_44_p6(double eta, double S, double chi1,
     return total;
 }
 
-
+/* End of Phase Parameter Space Fits */
 
 /************* PHASE ANSATZ ****************/
 
diff --git a/lalsimulation/lib/LALSimIMRPhenomXHM_intermediate.h b/lalsimulation/lib/LALSimIMRPhenomXHM_intermediate.h
index c5af3e66b7c0b87c6df4bf09a52e42eb016439b1..d99a6e5a920e69f4962e9817767f985d780fde12 100644
--- a/lalsimulation/lib/LALSimIMRPhenomXHM_intermediate.h
+++ b/lalsimulation/lib/LALSimIMRPhenomXHM_intermediate.h
@@ -48,24 +48,35 @@ extern "C" {
 /*********** AMPLITUDE *****************/
 
 //Fits int1, int2. 2 collocation points
-static double IMRPhenomXHM_Inter_Amp_21_int1(double eta, double S, double chi1, double chi2, int InterAmpFlag);
-static double IMRPhenomXHM_Inter_Amp_21_int2(double eta, double S, double chi1, double chi2, int InterAmpFlag);
-static double IMRPhenomXHM_Inter_Amp_33_int1(double eta, double S, double chi1, double chi2, int InterAmpFlag);
-static double IMRPhenomXHM_Inter_Amp_33_int2(double eta, double S, double chi1, double chi2, int InterAmpFlag);
-static double IMRPhenomXHM_Inter_Amp_32_int1(double eta, double S, double chi1, double chi2, int InterAmpFlag);
-static double IMRPhenomXHM_Inter_Amp_32_int2(double eta, double S, double chi1, double chi2, int InterAmpFlag);
-static double IMRPhenomXHM_Inter_Amp_44_int1(double eta, double S, double chi1, double chi2, int InterAmpFlag);
-static double IMRPhenomXHM_Inter_Amp_44_int2(double eta, double S, double chi1, double chi2, int InterAmpFlag);
+static double IMRPhenomXHM_Inter_Amp_21_int1(IMRPhenomXWaveformStruct *pWF, int InterAmpFlag);
+static double IMRPhenomXHM_Inter_Amp_21_int2(IMRPhenomXWaveformStruct *pWF, int InterAmpFlag);
+static double IMRPhenomXHM_Inter_Amp_33_int1(IMRPhenomXWaveformStruct *pWF, int InterAmpFlag);
+static double IMRPhenomXHM_Inter_Amp_33_int2(IMRPhenomXWaveformStruct *pWF, int InterAmpFlag);
+static double IMRPhenomXHM_Inter_Amp_32_int1(IMRPhenomXWaveformStruct *pWF, int InterAmpFlag);
+static double IMRPhenomXHM_Inter_Amp_32_int2(IMRPhenomXWaveformStruct *pWF, int InterAmpFlag);
+static double IMRPhenomXHM_Inter_Amp_44_int1(IMRPhenomXWaveformStruct *pWF, int InterAmpFlag);
+static double IMRPhenomXHM_Inter_Amp_44_int2(IMRPhenomXWaveformStruct *pWF, int InterAmpFlag);
+static double IMRPhenomXHM_Inter_Amp_21_int3(IMRPhenomXWaveformStruct *pWF, int InterAmpFlag);
+static double IMRPhenomXHM_Inter_Amp_21_int4(IMRPhenomXWaveformStruct *pWF, int InterAmpFlag);
+static double IMRPhenomXHM_Inter_Amp_33_int3(IMRPhenomXWaveformStruct *pWF, int InterAmpFlag);
+static double IMRPhenomXHM_Inter_Amp_33_int4(IMRPhenomXWaveformStruct *pWF, int InterAmpFlag);
+static double IMRPhenomXHM_Inter_Amp_32_int3(IMRPhenomXWaveformStruct *pWF, int InterAmpFlag);
+static double IMRPhenomXHM_Inter_Amp_32_int4(IMRPhenomXWaveformStruct *pWF, int InterAmpFlag);
+static double IMRPhenomXHM_Inter_Amp_44_int3(IMRPhenomXWaveformStruct *pWF, int InterAmpFlag);
+static double IMRPhenomXHM_Inter_Amp_44_int4(IMRPhenomXWaveformStruct *pWF, int InterAmpFlag);
+
+/* End of Parameter Space Fits */
 
 //Fits int0, dint0. Extra collocation point for EMR cases
-static double IMRPhenomXHM_Inter_Amp_21_int0(double eta, double S, double chi1, double chi2, int InterAmpFlag);
-static double IMRPhenomXHM_Inter_Amp_21_dint0(double eta, double S, double chi1, double chi2, int InterAmpFlag);
-static double IMRPhenomXHM_Inter_Amp_33_int0(double eta, double S, double chi1, double chi2, int InterAmpFlag);
-static double IMRPhenomXHM_Inter_Amp_33_dint0(double eta, double S, double chi1, double chi2, int InterAmpFlag);
-static double IMRPhenomXHM_Inter_Amp_32_int0(double eta, double S, double chi1, double chi2, int InterAmpFlag);
-static double IMRPhenomXHM_Inter_Amp_32_dint0(double eta, double S, double chi1, double chi2, int InterAmpFlag);
-static double IMRPhenomXHM_Inter_Amp_44_int0(double eta, double S, double chi1, double chi2, int InterAmpFlag);
-static double IMRPhenomXHM_Inter_Amp_44_dint0(double eta, double S, double chi1, double chi2, int InterAmpFlag);
+static double IMRPhenomXHM_Inter_Amp_21_int0(IMRPhenomXWaveformStruct *pWF, int InterAmpFlag);
+static double IMRPhenomXHM_Inter_Amp_21_dint0(IMRPhenomXWaveformStruct *pWF, int InterAmpFlag);
+static double IMRPhenomXHM_Inter_Amp_33_int0(IMRPhenomXWaveformStruct *pWF, int InterAmpFlag);
+static double IMRPhenomXHM_Inter_Amp_33_dint0(IMRPhenomXWaveformStruct *pWF, int InterAmpFlag);
+static double IMRPhenomXHM_Inter_Amp_32_int0(IMRPhenomXWaveformStruct *pWF, int InterAmpFlag);
+static double IMRPhenomXHM_Inter_Amp_32_dint0(IMRPhenomXWaveformStruct *pWF, int InterAmpFlag);
+static double IMRPhenomXHM_Inter_Amp_44_int0(IMRPhenomXWaveformStruct *pWF, int InterAmpFlag);
+static double IMRPhenomXHM_Inter_Amp_44_dint0(IMRPhenomXWaveformStruct *pWF, int InterAmpFlag);
+
 
 //Coefficients of polynomial. They are feed with the some collocation points.
 static double IMRPhenomXHM_Intermediate_Amp_delta0(double d1, double d4, double v1, double v2, double v3, double v4, double f1, double f2, double f3, double f4, int IntAmpFlag);
@@ -76,7 +87,7 @@ static double IMRPhenomXHM_Intermediate_Amp_delta4(double d1, double d4, double
 static double IMRPhenomXHM_Intermediate_Amp_delta5(double d1, double d4, double v1, double v2, double v3, double v4, double f1, double f2, double f3, double f4, int IntAmpFlag);
 
 //Ansatz. Inverse of a polynomial
-static double IMRPhenomXHM_Intermediate_Amp_Ansatz(IMRPhenomX_UsefulPowers *powers_of_f, IMRPhenomXHMAmpCoefficients *pAmp);
+static double IMRPhenomXHM_Intermediate_Amp_Ansatz(IMRPhenomX_UsefulPowers *powers_of_f, IMRPhenomXHMWaveformStruct *pWFHM, IMRPhenomXHMAmpCoefficients *pAmp);
 
 //Veto Functions
 static void IMRPhenomXHM_Intermediate_Amplitude_Veto(double *int1, double *int2, IMRPhenomXHMWaveformStruct *pWFHM, IMRPhenomXWaveformStruct *pWF22);
@@ -102,39 +113,41 @@ static void Update_Intermediate_Amplitude_Coefficients(IMRPhenomXHMAmpCoefficien
 //Check if the polynomials cross zero and lower the order if needed in an iterative way
 static void ChoosePolOrder(IMRPhenomXHMWaveformStruct *pWFHM, IMRPhenomXHMAmpCoefficients *pAmp);
 
+static void IMRPhenomXHM_Intermediate_Amp_CollocationPoints(IMRPhenomXHMAmpCoefficients *pAmp, IMRPhenomXHMWaveformStruct *pWFHM, IMRPhenomXWaveformStruct *pWF22, IMRPhenomXHMPhaseCoefficients *pPhase, IMRPhenomXAmpCoefficients *pAmp22, IMRPhenomXPhaseCoefficients *pPhase22);
+void IMRPhenomXHM_Intermediate_Amp_Coefficients(IMRPhenomXHMAmpCoefficients *pAmp, IMRPhenomXHMWaveformStruct *pWFHM, IMRPhenomXWaveformStruct *pWF22, IMRPhenomXHMPhaseCoefficients *pPhase, IMRPhenomXAmpCoefficients *pAmp22, IMRPhenomXPhaseCoefficients *pPhase22);
 
 /************** PHASE ******************/
 
 //Fits of the collocation points across paramter space
-static double IMRPhenomXHM_Inter_Phase_21_p1(double eta, double S, double chi1, double chi2, int);
-static double IMRPhenomXHM_Inter_Phase_21_p2(double eta, double S, double chi1, double chi2, int);
-static double IMRPhenomXHM_Inter_Phase_21_p3(double eta, double S, double chi1, double chi2, int);
-static double IMRPhenomXHM_Inter_Phase_21_p4(double eta, double S, double chi1, double chi2, int);
-static double IMRPhenomXHM_Inter_Phase_21_p5(double eta, double S, double chi1, double chi2, int);
-static double IMRPhenomXHM_Inter_Phase_21_p6(double eta, double S, double chi1, double chi2, int);
-
-
-static double IMRPhenomXHM_Inter_Phase_33_p1(double eta, double S, double chi1, double chi2, int);
-static double IMRPhenomXHM_Inter_Phase_33_p2(double eta, double S, double chi1, double chi2, int);
-static double IMRPhenomXHM_Inter_Phase_33_p3(double eta, double S, double chi1, double chi2, int);
-static double IMRPhenomXHM_Inter_Phase_33_p4(double eta, double S, double chi1, double chi2, int);
-static double IMRPhenomXHM_Inter_Phase_33_p5(double eta, double S, double chi1, double chi2, int);
-static double IMRPhenomXHM_Inter_Phase_33_p6(double eta, double S, double chi1, double chi2, int);
-
-static double IMRPhenomXHM_Inter_Phase_32_p1(double eta, double S, double chi1, double chi2, int);
-static double IMRPhenomXHM_Inter_Phase_32_p2(double eta, double S, double chi1, double chi2, int);
-static double IMRPhenomXHM_Inter_Phase_32_p3(double eta, double S, double chi1, double chi2, int);
-static double IMRPhenomXHM_Inter_Phase_32_p4(double eta, double S, double chi1, double chi2, int);
-static double IMRPhenomXHM_Inter_Phase_32_p5(double eta, double S, double chi1, double chi2, int);
-static double IMRPhenomXHM_Inter_Phase_32_p6(double eta, double S, double chi1, double chi2, int);
-
-
-static double IMRPhenomXHM_Inter_Phase_44_p1(double eta, double S, double chi1, double chi2, int);
-static double IMRPhenomXHM_Inter_Phase_44_p2(double eta, double S, double chi1, double chi2, int);
-static double IMRPhenomXHM_Inter_Phase_44_p3(double eta, double S, double chi1, double chi2, int);
-static double IMRPhenomXHM_Inter_Phase_44_p4(double eta, double S, double chi1, double chi2, int);
-static double IMRPhenomXHM_Inter_Phase_44_p5(double eta, double S, double chi1, double chi2, int);
-static double IMRPhenomXHM_Inter_Phase_44_p6(double eta, double S, double chi1, double chi2, int);
+static double IMRPhenomXHM_Inter_Phase_21_p1(IMRPhenomXWaveformStruct *pWF, int);
+static double IMRPhenomXHM_Inter_Phase_21_p2(IMRPhenomXWaveformStruct *pWF, int);
+static double IMRPhenomXHM_Inter_Phase_21_p3(IMRPhenomXWaveformStruct *pWF, int);
+static double IMRPhenomXHM_Inter_Phase_21_p4(IMRPhenomXWaveformStruct *pWF, int);
+static double IMRPhenomXHM_Inter_Phase_21_p5(IMRPhenomXWaveformStruct *pWF, int);
+static double IMRPhenomXHM_Inter_Phase_21_p6(IMRPhenomXWaveformStruct *pWF, int);
+
+
+static double IMRPhenomXHM_Inter_Phase_33_p1(IMRPhenomXWaveformStruct *pWF, int);
+static double IMRPhenomXHM_Inter_Phase_33_p2(IMRPhenomXWaveformStruct *pWF, int);
+static double IMRPhenomXHM_Inter_Phase_33_p3(IMRPhenomXWaveformStruct *pWF, int);
+static double IMRPhenomXHM_Inter_Phase_33_p4(IMRPhenomXWaveformStruct *pWF, int);
+static double IMRPhenomXHM_Inter_Phase_33_p5(IMRPhenomXWaveformStruct *pWF, int);
+static double IMRPhenomXHM_Inter_Phase_33_p6(IMRPhenomXWaveformStruct *pWF, int);
+
+static double IMRPhenomXHM_Inter_Phase_32_p1(IMRPhenomXWaveformStruct *pWF, int);
+static double IMRPhenomXHM_Inter_Phase_32_p2(IMRPhenomXWaveformStruct *pWF, int);
+static double IMRPhenomXHM_Inter_Phase_32_p3(IMRPhenomXWaveformStruct *pWF, int);
+static double IMRPhenomXHM_Inter_Phase_32_p4(IMRPhenomXWaveformStruct *pWF, int);
+static double IMRPhenomXHM_Inter_Phase_32_p5(IMRPhenomXWaveformStruct *pWF, int);
+static double IMRPhenomXHM_Inter_Phase_32_p6(IMRPhenomXWaveformStruct *pWF, int);
+
+
+static double IMRPhenomXHM_Inter_Phase_44_p1(IMRPhenomXWaveformStruct *pWF, int);
+static double IMRPhenomXHM_Inter_Phase_44_p2(IMRPhenomXWaveformStruct *pWF, int);
+static double IMRPhenomXHM_Inter_Phase_44_p3(IMRPhenomXWaveformStruct *pWF, int);
+static double IMRPhenomXHM_Inter_Phase_44_p4(IMRPhenomXWaveformStruct *pWF, int);
+static double IMRPhenomXHM_Inter_Phase_44_p5(IMRPhenomXWaveformStruct *pWF, int);
+static double IMRPhenomXHM_Inter_Phase_44_p6(IMRPhenomXWaveformStruct *pWF, int);
 
 //Ansatz
 static double IMRPhenomXHM_Inter_Phase_Ansatz(double ff, IMRPhenomX_UsefulPowers *powers_of_f,IMRPhenomXHMWaveformStruct *pWFHM, IMRPhenomXHMPhaseCoefficients *pPhase);
diff --git a/lalsimulation/lib/LALSimIMRPhenomXHM_internals.c b/lalsimulation/lib/LALSimIMRPhenomXHM_internals.c
index 2355812a0c69fbd9cd2fa9c9d24f445264630fa4..fd86832c1eff0aa765d3695e18631b7681c2fadb 100644
--- a/lalsimulation/lib/LALSimIMRPhenomXHM_internals.c
+++ b/lalsimulation/lib/LALSimIMRPhenomXHM_internals.c
@@ -32,10 +32,12 @@
 #include "LALSimIMRPhenomX_internals.h"
 #include "LALSimIMRPhenomXUtilities.h"
 
+
+#include "LALSimIMRPhenomXHM_inspiral.c"//Change2
+
 #include "LALSimIMRPhenomXHM_ringdown.c"
 #include "LALSimIMRPhenomXHM_intermediate.c"
-#include "LALSimIMRPhenomXHM_inspiral.c"
-
+// Change 2#include "LALSimIMRPhenomXHM_inspiral.c"
 
 /*Equations referenced in this file come from arXiv:2001.10914 [gr-qc], see also dcc:LIGO-P2000011 */
 
@@ -69,10 +71,10 @@ void IMRPhenomXHM_Initialize_MixingCoeffs(IMRPhenomXHMWaveformStruct *wf, IMRPhe
 
   #if DEBUG == 1
   printf("\nMixing coefficients:\n");
-  printf("re(a222)=%f,im(a222)=%f \n",evaluate_QNMfit_re_l2m2lp2(wf22->afinal),evaluate_QNMfit_im_l2m2lp2(wf22->afinal));
-  printf("re(a223)=%f,im(a223)=%f \n",evaluate_QNMfit_re_l2m2lp3(wf22->afinal),evaluate_QNMfit_im_l2m2lp3(wf22->afinal));
-  printf("re(a322)=%f,im(a322)=%f \n",evaluate_QNMfit_re_l3m2lp2(wf22->afinal),evaluate_QNMfit_im_l3m2lp2(wf22->afinal));
-  printf("re(a323)=%f,im(a323)=%f \n",evaluate_QNMfit_re_l3m2lp3(wf22->afinal),evaluate_QNMfit_im_l3m2lp3(wf22->afinal));
+  printf("re(a222)=%.16e,im(a222)=%.16e \n",evaluate_QNMfit_re_l2m2lp2(wf22->afinal),evaluate_QNMfit_im_l2m2lp2(wf22->afinal));
+  printf("re(a223)=%.16e,im(a223)=%.16e \n",evaluate_QNMfit_re_l2m2lp3(wf22->afinal),evaluate_QNMfit_im_l2m2lp3(wf22->afinal));
+  printf("re(a322)=%.16e,im(a322)=%.16e \n",evaluate_QNMfit_re_l3m2lp2(wf22->afinal),evaluate_QNMfit_im_l3m2lp2(wf22->afinal));
+  printf("re(a323)=%.16e,im(a323)=%.16e \n",evaluate_QNMfit_re_l3m2lp3(wf22->afinal),evaluate_QNMfit_im_l3m2lp3(wf22->afinal));
   #endif
 }
 
@@ -95,40 +97,25 @@ void IMRPhenomXHM_SetHMWaveformVariables(
   wf->ampNorm = wf22->ampNorm;
   wf->fMECOlm = wf22->fMECO*emm*0.5;
   wf->Ampzero = 0;                       // Ampzero = 1 (true) for odd modes and equal black holes
-  wf->Amp0 = wf22->ampNorm * wf22->amp0;
+  wf->Amp0 = wf22->amp0;// * wf22->ampNorm;
   wf->useFAmpPN = 0;                     // Only true for the 21, this mode has a different inspiral ansatz
-  if(wf22->eta < 0.013886133703630232 && wf22->chi1L<=0.9){ // For q>70 and chi1<0.9 use two intermediate regions.
-    wf->AmpEMR = 1;                                         // These cases have a more pronounced drop off in the amplitude at the end of the inspiral and need two intermediate regions to model it.
-  }
-  else{
-    wf->AmpEMR = 0;
-  }
+  wf->AmpEMR = 0; // Only one intermediate region
+  wf->InspiralAmpVeto=0;
+  wf->IntermediateAmpVeto=0;
+  wf->RingdownAmpVeto=0;
+  
   switch(wf->modeTag){
     case 21:{
       wf->modeInt=0;
       wf->MixingOn=0;
-      if(wf22->q < 8.){
-        wf->InspiralAmpVeto=1;
-        wf->IntermediateAmpVeto=1;
-      }else{
-        wf->InspiralAmpVeto=0;
-        wf->IntermediateAmpVeto=0;
-      }
-      wf->RingdownAmpVeto=1;
       if(wf22->q == 1. && wf22->chi1L == wf22->chi2L){  // Odd mode for equal mass, equal spin is zero
         wf->Ampzero = 1;
       }
-      if(wf22->eta >= 0.0237954){ //for EMR (q>40.)
-        wf->useFAmpPN = 1;
-      }
       break;
     }
     case 33:{
       wf->modeInt=1;
       wf->MixingOn=0;
-      wf->InspiralAmpVeto=0;
-      wf->IntermediateAmpVeto=0;
-      wf->RingdownAmpVeto=0;
       if(wf22->q == 1. && wf22->chi1L == wf22->chi2L){  // Odd mode for equal mass, equal spin is zero
         wf->Ampzero = 1;
       }
@@ -137,17 +124,11 @@ void IMRPhenomXHM_SetHMWaveformVariables(
     case 32:{            //Mode with Mixing
       wf->modeInt=2;
       wf->MixingOn=1;
-      wf->InspiralAmpVeto=0;
-      wf->IntermediateAmpVeto=0;
-      wf->RingdownAmpVeto=1;
       break;
     }
     case 44:{
       wf->modeInt=3;
       wf->MixingOn=0;
-      wf->InspiralAmpVeto=0;
-      wf->IntermediateAmpVeto=0;
-      wf->RingdownAmpVeto=0;
       break;
     }
     default:
@@ -157,28 +138,162 @@ void IMRPhenomXHM_SetHMWaveformVariables(
     /* Here we select the version of the fits and of the reconstruction that will be used in the code.
        Through XLALSimInspiralWaveformParamsLookupPhenomXHM(Inspiral/Intermediate/Ringdown)(Amp/Phase)Version we call the version of the fits used by the phase in each region.
        Currently there is only one version available and is tagged by the release date in the format mmyyyy (122019)*/
+  wf->IMRPhenomXHMReleaseVersion             = XLALSimInspiralWaveformParamsLookupPhenomXHMReleaseVersion(LALParams); // 122019
+
   wf->IMRPhenomXHMInspiralPhaseVersion       = XLALSimInspiralWaveformParamsLookupPhenomXHMInspiralPhaseVersion(LALParams);//122019
   wf->IMRPhenomXHMIntermediatePhaseVersion   = XLALSimInspiralWaveformParamsLookupPhenomXHMIntermediatePhaseVersion(LALParams); //122019
   wf->IMRPhenomXHMRingdownPhaseVersion       = XLALSimInspiralWaveformParamsLookupPhenomXHMRingdownPhaseVersion(LALParams); //122019
+  
   wf->IMRPhenomXHMInspiralAmpFitsVersion     = XLALSimInspiralWaveformParamsLookupPhenomXHMInspiralAmpFitsVersion(LALParams); //122018
   wf->IMRPhenomXHMIntermediateAmpFitsVersion = XLALSimInspiralWaveformParamsLookupPhenomXHMIntermediateAmpFitsVersion(LALParams); //122018
   wf->IMRPhenomXHMRingdownAmpFitsVersion     = XLALSimInspiralWaveformParamsLookupPhenomXHMRingdownAmpFitsVersion(LALParams); //122018
+  
+  wf->IMRPhenomXHMInspiralAmpFreqsVersion    = XLALSimInspiralWaveformParamsLookupPhenomXHMInspiralAmpFreqsVersion(LALParams); //122018
+  wf->IMRPhenomXHMIntermediateAmpFreqsVersion= XLALSimInspiralWaveformParamsLookupPhenomXHMIntermediateAmpFreqsVersion(LALParams); //122018
+  wf->IMRPhenomXHMRingdownAmpFreqsVersion    = XLALSimInspiralWaveformParamsLookupPhenomXHMRingdownAmpFreqsVersion(LALParams); //122018
+ 
   /* Reconstruction version for the amplitude */
   wf->IMRPhenomXHMInspiralAmpVersion         = XLALSimInspiralWaveformParamsLookupPhenomXHMInspiralAmpVersion(LALParams); //3  (3 collocation points)
   wf->IMRPhenomXHMIntermediateAmpVersion     = XLALSimInspiralWaveformParamsLookupPhenomXHMIntermediateAmpVersion(LALParams); //2   (2 collocation points)
   wf->IMRPhenomXHMRingdownAmpVersion         = XLALSimInspiralWaveformParamsLookupPhenomXHMRingdownAmpVersion(LALParams); //0  (0 collocation points)
 
 
-  // Default collocation points for amplitude
-  wf->nCollocPtsInspAmp  = wf->IMRPhenomXHMInspiralAmpVersion;
-  wf->nCollocPtsInterAmp = wf->IMRPhenomXHMIntermediateAmpVersion;
+  wf->IMRPhenomXHMInspiralPhaseFitsVersion = wf->IMRPhenomXHMInspiralPhaseVersion;
+  wf->IMRPhenomXHMIntermediatePhaseFitsVersion = wf->IMRPhenomXHMIntermediatePhaseVersion;
+  wf->IMRPhenomXHMRingdownPhaseFitsVersion = wf->IMRPhenomXHMRingdownPhaseVersion;
 
-  if(wf->modeTag==32){ wf->nCollocPtsInterPhase=6;}
-  else {wf->nCollocPtsInterPhase=5;}
+  wf->IMRPhenomXHMInspiralPhaseFreqsVersion = wf->IMRPhenomXHMInspiralPhaseVersion;
+  wf->IMRPhenomXHMIntermediatePhaseFreqsVersion = wf->IMRPhenomXHMIntermediatePhaseVersion;
+  wf->IMRPhenomXHMRingdownPhaseFreqsVersion = wf->IMRPhenomXHMRingdownPhaseVersion;
+
+  wf->nCollocPtsRDPhase = 0;
+  
+  if (wf->IMRPhenomXHMReleaseVersion == 122019){
+      if(wf22->eta < 0.013886133703630232 && wf22->chi1L<=0.9){ // For q>70 and chi1<0.9 use two intermediate regions.
+        wf->AmpEMR = 1;                                         // These cases have a more pronounced drop off in the amplitude at the end of the inspiral and need two intermediate regions to model it.
+      }      
+      switch(wf->modeTag){
+        case 21:{
+          if(wf22->q < 8.){
+            wf->InspiralAmpVeto=1;
+            wf->IntermediateAmpVeto=1;
+          }
+          wf->RingdownAmpVeto=1;
+          if(wf22->eta >= 0.0237954){ //for EMR (q>40.)
+            wf->useFAmpPN = 1;
+          }
+          break;
+        }
+        case 33:{
+          if(wf22->q == 1. && wf22->chi1L == wf22->chi2L){  // Odd mode for equal mass, equal spin is zero
+            wf->Ampzero = 1;
+          }
+          break;
+        }
+        case 32:{            //Mode with Mixing
+          wf->RingdownAmpVeto=1;
+          wf->nCollocPtsRDPhase = 4;
+          break;
+        }
+        case 44:{
+          break;
+        }
+        default:
+          {XLALPrintError("Error in IMRPhenomXHM_SetHMWaveformVariables: mode (%i,%i) selected is not currently available. Modes available are ((2,|2|),(2,|1|),(3,|2|),(3,|3|),(4,|4|)).\n", wf->ell, wf->emm);}
+      }
+      wf->nCollocPtsInspAmp = wf->IMRPhenomXHMInspiralAmpVersion;
+      wf->nCollocPtsInterAmp = wf->IMRPhenomXHMIntermediateAmpVersion;
+      wf->IMRPhenomXHMRingdownPhaseFreqsVersion = 122019;
+  }  
+  else if (wf->IMRPhenomXHMReleaseVersion == 122022)
+  {
+      /* Here we change the versions for the collocation point frequencies, parameter space fits and ansatzaes for both amplitude and phase.
+         It is better to do it here instead of changing the default values in SimInspiralWaveformParams.c.
+         For a new release, copy this else if block and use it as a template. */
+      
+      /* Amplitude */
+      
+      // Versions for the cutting and collocation points frequencies
+      wf->IMRPhenomXHMInspiralAmpFreqsVersion     = 122022;
+      wf->IMRPhenomXHMIntermediateAmpFreqsVersion = 0;
+      wf->IMRPhenomXHMRingdownAmpFreqsVersion     = 122022;
+      // Versions for the parameter space fits of coefficients or collocation points
+      wf->IMRPhenomXHMInspiralAmpFitsVersion     = 122022;
+      wf->IMRPhenomXHMIntermediateAmpFitsVersion = 122022;
+      wf->IMRPhenomXHMRingdownAmpFitsVersion     = 122022;
+      // Versions for the ansatzaes
+      wf->IMRPhenomXHMInspiralAmpVersion     = 123;
+      wf->IMRPhenomXHMIntermediateAmpVersion = 211112;
+      wf->IMRPhenomXHMRingdownAmpVersion     = 2;
+      
+      /* Notes for the new release and beyond:
+         - IMRPhenomXHMInspiralAmpVersion: 
+                                           assuming that we have 3 collocation points, it indicates which collocation points are going to be used in the reconstruction.
+                                           e.g.: 123 means we use the three, 13 means we only use the 1st and the 3rd; 2 means we only use the 2nd, etc.
+         - IMRPhenomXHMIntermediateAmpVersion: 
+                                           the number of digits indicate the number of collocation points in the intermediate part.
+                                           in this case we have 6 digits which relates to the 4 fitted collocation points + 2 boundaries
+                                           if the digit is 0 then we discard that collocation point
+                                           if the digit is 1 we use the value of the amplitude at that frequency
+                                           if the digit is 2 we use the value and the derivative of the derivative amplitude at that frequency
+                                           the digit 2 can only really go in the boundaries since the inner points are fixed parameter space fits of the amplitude value
+                                           at the boundaries we can use the inspiral or ringdown ansatz to compute the derivative
+                                           e.g.: 211112 means we will use the 4 parameter space fits + 2 value + 2 derivative at the boundaries = 8 degrees of freedom
+                                           e.g.: 110012 means we skip the left derivative and the two inner most collocation points = 5 degrees of freedom
+         - IMRPhenomXHMRingdownAmpVersion:
+                                           this is just an index for the different ansatz versions 
+                                           currently it only takes 0 (old release) and 1 (122022 release)
+        */
+      
+      
+      // Mode specific tweaks for amplitude
+      if (wf->modeTag == 21){
+          /* The 21 behaves better if we skip the left the derivative.
+             The drawback is that for cases with drop the inspiral-intermediate transition will not be derivable.
+             We also drop two collocation points in the middle to avoid wavy behaviour in the extrapolation region */
+          wf->IMRPhenomXHMIntermediateAmpVersion = 110102;
+      }
+      else if (wf->modeTag == 32){
+          // Use fit of coefficients instead of collocation points
+          wf->IMRPhenomXHMRingdownAmpVersion = 1;
+      }
+      
+      // As mentioned above, the number of digits in IMRPhenomXHMInsp(Intermediate)AmpVersion gives the number of collocation points for the inspiral(intermediate) part
+      wf->nCollocPtsInspAmp  = snprintf(NULL, 0, "%i", wf->IMRPhenomXHMInspiralAmpVersion);
+      wf->nCollocPtsInterAmp = snprintf(NULL, 0, "%i", wf->IMRPhenomXHMIntermediateAmpVersion);
+      
+      
+      /* Phase */
+      /* HM Phase is unchanged respect to the old release */
+      if (wf->modeTag == 32){wf->nCollocPtsRDPhase = 4;}
+      
+      /* Uncommenting the code below will employ a recalibration of the spheroidal phase for the 32.
+         This includes the collocation points for the derivative and the extra time and phase shift respect the 22 mode.
+         This can introduce introduce significant mismatch in the multimode waveform in the region without NR, so it is left for the next update. */
+      // if (wf->modeTag == 32){
+      //   wf->IMRPhenomXHMIntermediatePhaseFreqsVersion = 122022;
+      //   wf->IMRPhenomXHMRingdownPhaseFreqsVersion = 122022;
+      //   wf->IMRPhenomXHMRingdownPhaseFitsVersion  = 122022;
+      //   wf->IMRPhenomXHMRingdownPhaseVersion      = 122022;
+      //   wf->nCollocPtsRDPhase = 5;
+      // }
+
+      
+            
+  }
+  else{
+    XLAL_ERROR_VOID(XLAL_EDOM, "Error in IMRPhenomXHM_SetHMWaveformVariables: IMRPhenomXHMReleaseVersion=%i is not valid.\n", wf->IMRPhenomXHMReleaseVersion);
+  }
+    
+  /* Common for all releases */
+    
+  if(wf->modeTag==32){ 
+      wf->nCollocPtsInterPhase=6;
+  }
+  else{
+      wf->nCollocPtsInterPhase=5;
+  }
 
-  /* Phase : Ringdown */
-  wf->nCollocPtsRDPhase= 0;
-  if(wf->modeTag==32) {wf->nCollocPtsRDPhase=N_MAX_COEFFICIENTS_PHASE_RING;}
 
   /* Limit between comparable and extreme mass ratios for the phase */
   wf->etaEMR=0.05;
@@ -204,6 +319,9 @@ void IMRPhenomXHM_SetHMWaveformVariables(
   REAL8 psi4tostrain=XLALSimIMRPhenomXPsi4ToStrain(wf22->eta, wf22->STotR, wf22->dchi);
   wf->DeltaT= -2.*LAL_PI*(500+psi4tostrain);
 
+  wf->fPhaseRDflat = 0.0;
+  wf->fAmpRDfalloff = 0.0;
+
 }
 
 /* Store function names containing phase coefficient/collocation point fits in pPhase->[Inspiral|Intermediate|Ringdown]PhaseFits */
@@ -253,11 +371,11 @@ void IMRPhenomXHM_FillPhaseFitsArray(IMRPhenomXHMPhaseCoefficients *pPhase){
   pPhase->IntermediatePhaseFits[23]=IMRPhenomXHM_Inter_Phase_44_p6;
 
   //32 Spheroidal
-  pPhase->RingdownPhaseFits[0]=IMRPhenomXHM_Ringdown_Phase_32_p1;
-  pPhase->RingdownPhaseFits[1]=IMRPhenomXHM_Ringdown_Phase_32_p2;
-  pPhase->RingdownPhaseFits[2]=IMRPhenomXHM_Ringdown_Phase_32_p3;
-  pPhase->RingdownPhaseFits[3]=IMRPhenomXHM_Ringdown_Phase_32_p4;
-
+  pPhase->RingdownPhaseFits[0]=IMRPhenomXHM_RD_Phase_32_p1;
+  pPhase->RingdownPhaseFits[1]=IMRPhenomXHM_RD_Phase_32_p2;
+  pPhase->RingdownPhaseFits[2]=IMRPhenomXHM_RD_Phase_32_p3;
+  pPhase->RingdownPhaseFits[3]=IMRPhenomXHM_RD_Phase_32_p4;
+  pPhase->RingdownPhaseFits[4]=IMRPhenomXHM_RD_Phase_32_p5;
 
 }
 
@@ -326,6 +444,21 @@ void IMRPhenomXHM_FillAmpFitsArray(IMRPhenomXHMAmpCoefficients *pAmp){
   pAmp->IntermediateAmpFits[14] = IMRPhenomXHM_Inter_Amp_44_int0; //fcutInsp + (fInt1 - fcutInsp)/3
   pAmp->IntermediateAmpFits[15] = IMRPhenomXHM_Inter_Amp_44_dint0;//fcutInsp + (fInt1 - fcutInsp)/3
 
+  //21
+  pAmp->IntermediateAmpFits[16] = IMRPhenomXHM_Inter_Amp_21_int3;
+  pAmp->IntermediateAmpFits[17] = IMRPhenomXHM_Inter_Amp_21_int4;
+
+  //33
+  pAmp->IntermediateAmpFits[18] = IMRPhenomXHM_Inter_Amp_33_int3;
+  pAmp->IntermediateAmpFits[19] = IMRPhenomXHM_Inter_Amp_33_int4;
+
+  //32
+  pAmp->IntermediateAmpFits[20] = IMRPhenomXHM_Inter_Amp_32_int3;
+  pAmp->IntermediateAmpFits[21] = IMRPhenomXHM_Inter_Amp_32_int4;
+
+  //44
+  pAmp->IntermediateAmpFits[22] = IMRPhenomXHM_Inter_Amp_44_int3;
+  pAmp->IntermediateAmpFits[23] = IMRPhenomXHM_Inter_Amp_44_int4;
 
   /****Ringdown Fits for coefficients*****/
 
@@ -350,6 +483,32 @@ void IMRPhenomXHM_FillAmpFitsArray(IMRPhenomXHMAmpCoefficients *pAmp){
   pAmp->RingdownAmpFits[11] = IMRPhenomXHM_RD_Amp_44_sigma; //currently constant
 
 
+  /****Ringdown Fits for Collocation Points*****/
+
+  //21
+  pAmp->RingdownAmpFits[12]  = IMRPhenomXHM_RD_Amp_21_rdcp1;
+  pAmp->RingdownAmpFits[13]  = IMRPhenomXHM_RD_Amp_21_rdcp2;
+  pAmp->RingdownAmpFits[14]  = IMRPhenomXHM_RD_Amp_21_rdcp3;
+
+  //33
+  pAmp->RingdownAmpFits[15]  = IMRPhenomXHM_RD_Amp_33_rdcp1;
+  pAmp->RingdownAmpFits[16]  = IMRPhenomXHM_RD_Amp_33_rdcp2;
+  pAmp->RingdownAmpFits[17]  = IMRPhenomXHM_RD_Amp_33_rdcp3;
+
+  //32
+  pAmp->RingdownAmpFits[18]  = IMRPhenomXHM_RD_Amp_32_rdcp1;
+  pAmp->RingdownAmpFits[19]  = IMRPhenomXHM_RD_Amp_32_rdcp2;
+  pAmp->RingdownAmpFits[20]  = IMRPhenomXHM_RD_Amp_32_rdcp3;
+
+  //44
+  pAmp->RingdownAmpFits[21]  = IMRPhenomXHM_RD_Amp_44_rdcp1;
+  pAmp->RingdownAmpFits[22]  = IMRPhenomXHM_RD_Amp_44_rdcp2;
+  pAmp->RingdownAmpFits[23]  = IMRPhenomXHM_RD_Amp_44_rdcp3;
+
+  //32
+  pAmp->RingdownAmpFits[24]  = IMRPhenomXHM_RD_Amp_32_rdaux1;
+  pAmp->RingdownAmpFits[25]  = IMRPhenomXHM_RD_Amp_32_rdaux2;
+
 }
 
 
@@ -364,64 +523,79 @@ double IMRPhenomXHM_Amplitude_fcutInsp(IMRPhenomXHMWaveformStruct *pWFHM, IMRPhe
 
   //Return the end frequency of the inspiral region and the beginning of the intermediate for the amplitude of one mode.
 
-  int  version  = pWFHM->IMRPhenomXHMInspiralAmpFitsVersion;
+  int  version  = pWFHM->IMRPhenomXHMInspiralAmpFreqsVersion;
+  double fcut = 0.;   //Cutting frequency for comparable mass ratios
+  double fMECO  = pWFHM->fMECOlm;
   double emm    = 1.*(pWFHM->emm);
-  double fring  = pWFHM->fRING;
   double eta    = pWF22->eta;
   double chi1   = pWF22->chi1L;
-  double chieff = pWF22->chiEff;
-  double fMECO  = pWFHM->fMECOlm;
-  double fISCO  = (pWF22->fISCO)*emm*0.5;
-  double fcut = 0.;   //Cutting frequency for comparable mass ratios
   //fcutEMR is the cutting frequency for extreme mass ratios that is given by a fit to the frequncy of a particular geometrical structure of the amplitude
   double fcutEMR = 1.25*emm*((0.011671068725758493 - 0.0000858396080377194*chi1 + 0.000316707064291237*pow(chi1,2))*(0.8447212540381764 + 6.2873167352395125*eta))/(1.2857082764038923 - 0.9977728883419751*chi1);
 
   switch(version){
     case 122018: // default version
     {
-      switch(pWFHM->modeTag)
-      {
-        case 21:{
-          if(eta < 0.023795359904818562){ //for EMR (q>40.)
-            fcut = fcutEMR;
-          }
-          else{                //for comparable q
-            fcut = fMECO + (0.75-0.235*chieff - 5./6.*chieff*chieff)*fabs(fISCO-fMECO);
-          }
-          break;
-        }
-        case 33:{
-          if(eta < 0.04535147392290249){ //for EMR (q>20.)
-            fcut = fcutEMR;
-          }
-          else{                //for comparable q
-            fcut = fMECO + (0.75-0.235*chieff-5./6.*chieff)*fabs(fISCO-fMECO);
-          }
-          break;
+        
+        double fring  = pWFHM->fRING;
+        double chieff = pWF22->chiEff;
+        double fISCO  = (pWF22->fISCO)*emm*0.5;
+        
+        switch(pWFHM->modeTag)
+        {
+            case 21:{
+              if(eta < 0.023795359904818562){ //for EMR (q>40.)
+                fcut = fcutEMR;
+              }
+              else{                //for comparable q
+                fcut = fMECO + (0.75-0.235*chieff - 5./6.*chieff*chieff)*fabs(fISCO-fMECO);
+              }
+              break;
+            }
+            case 33:{
+              if(eta < 0.04535147392290249){ //for EMR (q>20.)
+                fcut = fcutEMR;
+              }
+              else{                //for comparable q
+                fcut = fMECO + (0.75-0.235*chieff-5./6.*chieff)*fabs(fISCO-fMECO);
+              }
+              break;
+            }
+            case 32:{
+              if(eta < 0.04535147392290249){ //for extreme mass ratios (q>20)
+                fcut = fcutEMR;
+              }
+              else{               //for comparable mass ratios
+                fcut = fMECO + (0.75-0.235*fabs(chieff))*fabs(fISCO-fMECO);
+                fcut = fcut*fring/pWF22->fRING;
+              }
+              break;
+            }
+            case 44:{
+              if(eta <  0.04535147392290249){  //for EMR (q>20)
+                fcut = fcutEMR;
+              }
+              else{                  //for comparable q
+                fcut = fMECO + (0.75-0.235*chieff)*fabs(fISCO-fMECO);
+              }
+              break;
+            }
         }
-        case 32:{
-          if(eta < 0.04535147392290249){ //for extreme mass ratios (q>20)
-            fcut = fcutEMR;
-          }
-          else{               //for comparable mass ratios
-            fcut = fMECO + (0.75-0.235*fabs(chieff))*fabs(fISCO-fMECO);
-            fcut = fcut*fring/pWF22->fRING;
-          }
-          break;
+        break;
+    }
+    case 122022:
+    {
+        if (pWF22->q < 20.){
+          fcut = fMECO;
         }
-        case 44:{
-          if(eta <  0.04535147392290249){  //for EMR (q>20)
-            fcut = fcutEMR;
-          }
-          else{                  //for comparable q
-            fcut = fMECO + (0.75-0.235*chieff)*fabs(fISCO-fMECO);
-          }
-          break;
+        else{
+          REAL8 transition_eta = 0.0192234; // q=50
+          REAL8 sharpness = 0.004;
+          REAL8 funcs = 0.5 + 0.5 * tanh((eta - transition_eta)/sharpness);
+          fcut = funcs * fMECO + (1 - funcs) * fcutEMR;
         }
-      }
-      break;
+        break;
     }
-    default: {XLALPrintError("Error in IMRPhenomXHM_Intermediate_CollocPtsFreqs: version is not valid. Version recommended is 122018.");}
+    default: {XLALPrintError("Error in IMRPhenomXHM_Amplitude_fcutInsp: version %i is not valid.", version);}
   }
   return fcut;
 }
@@ -432,7 +606,7 @@ double IMRPhenomXHM_Amplitude_fcutRD(IMRPhenomXHMWaveformStruct *pWFHM, IMRPheno
   //Returns the end of the intermediate region and the beginning of the ringdown for the amplitude of one mode
 
   double fring = pWFHM->fRING, fdamp=pWFHM->fDAMP;
-  int  version = pWFHM->IMRPhenomXHMRingdownAmpFitsVersion;
+  int  version = pWFHM->IMRPhenomXHMRingdownAmpFreqsVersion;
   double eta   = pWF22->eta;
   double chi1  = pWF22->chi1L;
   double fcut = 0.;  //This is the cutting frequency
@@ -473,7 +647,15 @@ double IMRPhenomXHM_Amplitude_fcutRD(IMRPhenomXHMWaveformStruct *pWFHM, IMRPheno
       }
       break;
     }
-    default: {XLALPrintError("Error in IMRPhenomXHM_Intermediate_CollocPtsFreqs: version is not valid. Version is recommended is 122018.");}
+    case 122022:
+    {
+        if(pWFHM->MixingOn == 1)
+            fcut = pWF22->fRING - 0.5*pWF22->fDAMP; //v8
+        else
+            fcut = fring - fdamp; //v2
+        break;
+    }
+    default: {XLALPrintError("Error in IMRPhenomXHM_Amplitude_fcutRD: version %i is not valid.", version);}
   }
   return fcut;
 }
@@ -499,10 +681,11 @@ void IMRPhenomXHM_Intermediate_CollocPtsFreqs(IMRPhenomXHMPhaseCoefficients *pPh
   //The frequencies are stored in the struct pPhase, which is initialized with new values as the code starts to work on each mode.
 
   double fring = pWFHM->fRING, fdamp=pWFHM->fDAMP;
-  int version  = pWFHM->IMRPhenomXHMIntermediatePhaseVersion;
+  int version  = pWFHM->IMRPhenomXHMIntermediatePhaseFreqsVersion;
 
     switch(version){
         case 122019: // default version
+        case 122022:
         {
             double fcut= GetfcutInsp(pWF22,pWFHM);
             pPhase->CollocationPointsFreqsPhaseInter[0]=fcut;
@@ -520,7 +703,9 @@ void IMRPhenomXHM_Intermediate_CollocPtsFreqs(IMRPhenomXHMPhaseCoefficients *pPh
                 pPhase->CollocationPointsFreqsPhaseInter[5]= fEnd;
                 pPhase->fPhaseMatchIM = fEnd;
                 // correct cutting frequency for EMR with negative spins
-                if(pWF22->eta<0.01&&pWF22->chi1L<0) pPhase->fPhaseMatchIM=pPhase->fPhaseMatchIM*(1.2-0.25*pWF22->chi1L);
+                if(pWF22->eta<0.01&&pWF22->chi1L<0 && version==122019){
+                  pPhase->fPhaseMatchIM=pPhase->fPhaseMatchIM*(1.2-0.25*pWF22->chi1L);
+                }
 
 
             }
@@ -554,10 +739,26 @@ void IMRPhenomXHM_Ringdown_CollocPtsFreqs(IMRPhenomXHMPhaseCoefficients *pPhase,
   double fringlm = pWFHM->fRING, fdamplm = pWFHM->fDAMP;
   double fring22 = pWF22->fRING;
 
-  pPhase->CollocationPointsFreqsPhaseRD[0] = fring22;
-  pPhase->CollocationPointsFreqsPhaseRD[2] = fringlm - 0.5*fdamplm;
-  pPhase->CollocationPointsFreqsPhaseRD[1] = fringlm - 1.5*fdamplm;
-  pPhase->CollocationPointsFreqsPhaseRD[3] = fringlm + 0.5*fdamplm;
+  switch(pWFHM->IMRPhenomXHMRingdownPhaseFreqsVersion){
+      case 122019:{
+        pPhase->CollocationPointsFreqsPhaseRD[0] = fring22;
+        pPhase->CollocationPointsFreqsPhaseRD[2] = fringlm - 0.5*fdamplm;
+        pPhase->CollocationPointsFreqsPhaseRD[1] = fringlm - 1.5*fdamplm;
+        pPhase->CollocationPointsFreqsPhaseRD[3] = fringlm + 0.5*fdamplm;
+        break;
+      }
+      case 122022:{
+        double fdamp22 = pWF22->fDAMP;
+        pPhase->CollocationPointsFreqsPhaseRD[0] = fring22 - fdamp22;
+        pPhase->CollocationPointsFreqsPhaseRD[1] = fring22;
+        pPhase->CollocationPointsFreqsPhaseRD[2] = (fring22 + fringlm) * 0.5;
+        pPhase->CollocationPointsFreqsPhaseRD[3] = fringlm;
+        pPhase->CollocationPointsFreqsPhaseRD[4] = fringlm + fdamplm;
+        break;
+      }
+      default:{XLAL_ERROR_VOID(XLAL_EINVAL,"Error in IMRPhenomXHM_Ringdown_CollocPtsFreqs: version %i is not valid.", pWFHM->IMRPhenomXHMRingdownPhaseFreqsVersion);}
+  }
+
 }
 
 
@@ -579,18 +780,18 @@ void IMRPhenomXHM_GetPNAmplitudeCoefficients(IMRPhenomXHMAmpCoefficients *pAmp,
 
   /* The coefficients below correspond to those in eqs E10-E14 in arXiv:2001.10914 */
 
-  int inspversion = pWFHM->IMRPhenomXHMInspiralAmpFitsVersion;
+  //int inspversion = pWFHM->IMRPhenomXHMInspiralAmpFitsVersion;
   double chiA = pWFHM->chi_a;
   double chiS = pWFHM->chi_s;
   double eta  = pWF22->eta, delta = pWF22->delta;
   double PI   = powers_of_lalpiHM.itself;
 
-  const double prefactors[] = {sqrt(2)/3., 0.75*sqrt(5/7.), sqrt(5/7.)/3., 4*sqrt(2)/9*sqrt(5/7.)};
+  const double prefactors[] = {sqrt(2)/3., 0.75*sqrt(5/7.), sqrt(5/7.)/3., 4*sqrt(2)/9*sqrt(5/7.)}; //Global factors of each PN hlm
   pAmp->PNglobalfactor = pow(2./(pWFHM->emm),-7/6.)*prefactors[pWFHM->modeInt]; //This is to compensate that we rescale data with the leading order of the 22
-
-  switch(inspversion){
+ 
+  /*switch(inspversion){  FIXMEE
     case 122018: // default version
-    {
+    {*/
       switch(pWFHM->modeTag)
       {
         case 21:{
@@ -651,11 +852,11 @@ void IMRPhenomXHM_GetPNAmplitudeCoefficients(IMRPhenomXHMAmpCoefficients *pAmp,
           pAmp->pnSixThirds = (7888301437 - 147113366400*chiA*chiS*delta - 745140957231*eta + 441340099200*chiA*chiS*delta*eta - 73556683200*chiA*chiA + 511264353600*eta*chiA*chiA - 73556683200*chiS*chiS + 224302478400*eta*chiS*chiS + 2271682065240*eta*eta - 871782912000*chiA*chiA*eta*eta - 10897286400*chiS*chiS*eta*eta - 805075876080*pow(eta,3))/2.90594304e10*powers_of_lalpiHM.two*powers_of_2d4.two;
           break;
         }
-      }
+    }/*
       break;
     }
     default: {XLALPrintError("Error in IMRPhenomXHM_GetPNAmplitudeCoefficients: version is not valid. Version recommended is 122018. ");}
-  }
+}*/
 }
 
 /*** Post-Newtonian Inspiral Ansatz Coefficients for the 21 mode ***/
@@ -748,608 +949,770 @@ void Get21PNAmplitudeCoefficients(IMRPhenomXHMAmpCoefficients *pAmp, IMRPhenomXW
 void IMRPhenomXHM_GetAmplitudeCoefficients(IMRPhenomXHMAmpCoefficients *pAmp, IMRPhenomXHMPhaseCoefficients *pPhase, IMRPhenomXAmpCoefficients *pAmp22, IMRPhenomXPhaseCoefficients *pPhase22, IMRPhenomXHMWaveformStruct *pWFHM, IMRPhenomXWaveformStruct *pWF22) {
 
     /* Take all the phenom coefficients accross the three regions (inspiral, intermeidate and ringdown) and all the needed parameters to reconstruct the amplitude (including mode-mixing). */
+    pAmp->ampNorm = pWF22->ampNorm;
+    pAmp->PNdominant = pWF22->ampNorm * pow(2./pWFHM->emm, -7/6.); // = Pi * Sqrt(2 eta/3) (2Pi /m)^(-7/6). Miss the f^(-7/6). The pi power included in ampNorm
+    switch(pWFHM->modeTag){
+        case 21:{
+            if(pWF22->q == 1){
+                pAmp->PNdominantlmpower = 2;
+                pAmp->PNdominantlm = sqrt(2.) / 3. * 1.5 * pWF22->dchi * 0.5 * pow(2 * LAL_PI / pWFHM->emm, 2/3.);
+            }
+            else{
+                pAmp->PNdominantlmpower = 1;
+                pAmp->PNdominantlm = sqrt(2.) / 3. * pWF22->delta * pow(2 * LAL_PI / pWFHM->emm, 1/3.);
+            }
+            break;
+        }
+        case 33:{
+            if(pWF22->q == 1){
+                pAmp->PNdominantlmpower = 4;
+                pAmp->PNdominantlm = 0.75 * sqrt(5./7) * pWF22->dchi * 0.5 * (65/24. - 28/3. * pWF22->eta) * pow(2 * LAL_PI / pWFHM->emm, 4/3.);
+            }
+            else{
+                pAmp->PNdominantlmpower = 1;
+                pAmp->PNdominantlm = 0.75 * sqrt(5./7) * pWF22->delta * pow(2 * LAL_PI / pWFHM->emm, 1/3.);
+            }
+            break;
+        }
+        case 32:{
+            pAmp->PNdominantlmpower = 2;
+            pAmp->PNdominantlm = 0.75 * sqrt(5./7) * pow(2 * LAL_PI / pWFHM->emm, 1/3.);
+            break;
+        }
+        case 44:{
+            pAmp->PNdominantlmpower = 2;
+            pAmp->PNdominantlm = 4/9. * sqrt(10/7.) * (1 - 3 * pWF22->eta) * pow(2 * LAL_PI / pWFHM->emm, 1/3.);
+            break;
+        }
+        default:
+          {XLALPrintError("Error in IMRPhenomXHM_GetAmplitudeCoefficients: mode selected is not currently available. Modes available are ((2,|2|),(2,|1|),(3,|2|),(3,|3|),(4,|4|)).\n");}
+    }
+    pAmp->PNdominantlm = fabs(pAmp->PNdominantlm);
+    pWFHM->fAmpRDfalloff = 0.;
+    pAmp->nCoefficientsInter = 0;
 
-    // Options for the extrapolation of the model outside the calibration region
-    if(((pWFHM->modeTag==44) || (pWFHM->modeTag==33)) && pWF22->q>7. && pWF22->chi1L > 0.95){
-      pAmp->useInspAnsatzRingdown = 1;
+    /*** Proceed region by region ***/
+    if(pWFHM->IMRPhenomXHMReleaseVersion != 122019){ 
+        pAmp->InspRescaleFactor = 0;
+        pAmp->RDRescaleFactor = 0;
+        pAmp->InterRescaleFactor = 0;
+                    
+            
+        /* Transform IMRPhenomXHMIntermediateAmpVersion number to int array defining what to do for each collocation point */
+        /* 0: don't use coll point, 1: use point, 2: use point and derivative (this only applies for boundaries) */
+        // e.g. pAmp->VersionCollocPtsInter = {1, 1, 1, 1, 0, 2} -> use the two boundaries, add derivative to the right one, skip third collocation point
+        UINT4 num = pWFHM->IMRPhenomXHMIntermediateAmpVersion;
+        for(UINT2 i = 0; i < pWFHM->nCollocPtsInterAmp; i++){
+            pAmp->VersionCollocPtsInter[pWFHM->nCollocPtsInterAmp - i - 1] = num % 10;
+            num/=10;
+        }
+
+        pAmp->nCoefficientsInter = 0;
+        for (UINT2 i = 0; i < pWFHM->nCollocPtsInterAmp; i++) pAmp->nCoefficientsInter += pAmp->VersionCollocPtsInter[i];
+        /* The number of coefficients in the intermediate ansatz cannot be larger than the number of available collocation points in IMRPhenomXHMIntermediateAmpVersion 
+           If e.g. IMRPhenomXHMIntermediateAmpVersion has 6 slots, the maximum number of coefficients would be 6 + 2 because we count for the derivatives at the boundaries. */
+        if (pAmp->nCoefficientsInter > pWFHM->nCollocPtsInterAmp + 2) 
+            XLAL_ERROR_VOID(XLAL_EFUNC, "IMRPhenomXHM_GetAmplitudeCoefficients failed. Inconsistent number of collocation points (%i) and free parameters (%i).", pWFHM->nCollocPtsInterAmp + 2, pAmp->nCoefficientsInter);
+
+        pAmp->nCoefficientsRDAux = 0;
+        if (pWFHM->MixingOn){
+            pAmp->nCollocPtsRDAux = 2;
+            pAmp->nCoefficientsRDAux = 4;
+            pAmp->fRDAux = pWFHM->fRING - pWFHM->fDAMP; //v2
+        }
+
+        // Take the cutting frequencies at the inspiral and ringdown
+        pAmp->fAmpMatchIN  = IMRPhenomXHM_Amplitude_fcutInsp(pWFHM, pWF22);
+        pAmp->fAmpMatchIM  = IMRPhenomXHM_Amplitude_fcutRD(pWFHM, pWF22);
+        pWFHM->fAmpRDfalloff = pWFHM->fRING + 2 * pWFHM->fDAMP;
+
+        /* Take Frequency Domain Post-Newtonian Amplitude Coefficients */
+        IMRPhenomXHM_GetPNAmplitudeCoefficients(pAmp, pWFHM, pWF22);
+
+        IMRPhenomXHM_Get_Inspiral_Amp_Coefficients(pAmp, pWFHM, pWF22);
+
+        IMRPhenomXHM_RD_Amp_Coefficients(pWF22, pWFHM, pAmp);
+                
+        IMRPhenomXHM_Intermediate_Amp_Coefficients(pAmp, pWFHM, pWF22, pPhase, pAmp22, pPhase22);
+
+        // printf("\nInsp Coll points\n");
+        // for(UINT2 i = 0; i < 3; i++){
+        //     printf("%.16f %.16e\n", pAmp->CollocationPointsFreqsAmplitudeInsp[i], pAmp->CollocationPointsValuesAmplitudeInsp[i]);
+        // }
+        // printf("\nInter Coll points\n");
+        // for(UINT2 i = 0; i < pAmp->nCoefficientsInter; i++){
+        //     printf("%.16f %.16e\n", pAmp->CollocationPointsFreqsAmplitudeInter[i], pAmp->CollocationPointsValuesAmplitudeInter[i]);
+        // }
+        // printf("\nRD Coll points\n");
+        // for(UINT2 i = 0; i < 3; i++){
+        //     printf("%.16f %.16e\n", pAmp->CollocationPointsFreqsAmplitudeRD[i], pAmp->CollocationPointsValuesAmplitudeRD[i]);
+        // }
+        // 
+        // printf("\nInsp Coefficients\n");
+        // for(UINT2 i = 0; i < 3; i++){
+        //     printf("%.16e\n", pAmp->InspiralCoefficient[i]);
+        // }
+        // printf("\nInter Coefficients %i\n", pAmp->nCoefficientsInter);
+        // for(UINT2 i = 0; i < pAmp->nCoefficientsInter; i++){
+        //     printf("%.16e\n", pAmp->InterCoefficient[i]);
+        // }
+        // printf("\nRD Coefficients\n");
+        // for(UINT2 i = 0; i < 5; i++){
+        //     printf("%.16e\n", pAmp->RDCoefficient[i]);
+        // }
+        // printf("\nRDAux Coll points\n");
+        // for(UINT2 i = 0; i < pAmp->nCoefficientsRDAux; i++){
+        //     printf("%.16f %.16e\n", pAmp->CollocationPointsFreqsAmplitudeRDAux[i], pAmp->CollocationPointsValuesAmplitudeRDAux[i]);
+        // }
+        // printf("\nRDAux Coefficients\n");
+        // for(UINT2 i = 0; i < pAmp->nCoefficientsRDAux; i++){
+        //     printf("%.16e\n", pAmp->RDAuxCoefficient[i]);
+        // }
+        
+
+        /* Set Rescale Factors to build Strain (=0) */
+        pAmp->InspRescaleFactor = 0;
+        pAmp->RDRescaleFactor = 0;
+        pAmp->InterRescaleFactor = 0;
     }
     else{
-      pAmp->useInspAnsatzRingdown = 0;
-    }
-    pAmp->WavyInsp = 0;
-    pAmp->WavyInt  = 0;
-    if(pWFHM->modeTag==21){
-      pAmp->WavyInsp = 1;
-      pAmp->WavyInt  = 1;
-    }
-    if(pWFHM->modeTag==32){
-      pAmp->WavyInsp = 1;
-    }
+        pAmp->InspRescaleFactor = 1;
+        pAmp->InterRescaleFactor = -1;
+        pAmp->RDRescaleFactor = 1;
 
-    // Take the cutting frequencies at the inspiral and ringdown
-    pAmp->fAmpMatchIN  = IMRPhenomXHM_Amplitude_fcutInsp(pWFHM, pWF22);
-    pAmp->fAmpMatchIM  = IMRPhenomXHM_Amplitude_fcutRD(pWFHM, pWF22);
+        // Options for the extrapolation of the model outside the calibration region
+        if(((pWFHM->modeTag==44) || (pWFHM->modeTag==33)) && pWF22->q>7. && pWF22->chi1L > 0.95){
+          pAmp->useInspAnsatzRingdown = 1;
+        }
+        else{
+          pAmp->useInspAnsatzRingdown = 0;
+        }
+        pAmp->WavyInsp = 0;
+        pAmp->WavyInt  = 0;
+        if(pWFHM->modeTag==21){
+          pAmp->WavyInsp = 1;
+          pAmp->WavyInt  = 1;
+        }
+        if(pWFHM->modeTag==32){
+          pAmp->WavyInsp = 1;
+        }
 
-    #if DEBUG == 1
-    printf("\n\n*** IMRPhenomXHM_GetAmplitudeCoefficients ***\n\n");
-    printf("fring_%i = %.16f\n", pWFHM->modeTag, pWFHM->fRING);
-    printf("fdamp_%i = %.16f\n", pWFHM->modeTag, pWFHM->fDAMP);
-    printf("fcutInsp_%i = %.16f \n", pWFHM->modeTag, pAmp->fAmpMatchIN);
-    printf("fcutRD_%i   = %.16f \n", pWFHM->modeTag, pAmp->fAmpMatchIM);
-    #endif
+        // Take the cutting frequencies at the inspiral and ringdown
+        pAmp->fAmpMatchIN  = IMRPhenomXHM_Amplitude_fcutInsp(pWFHM, pWF22);
+        pAmp->fAmpMatchIM  = IMRPhenomXHM_Amplitude_fcutRD(pWFHM, pWF22);
 
-    /* Compute the frequencies for Intermediate collocation points. */
-    /* It is done now because with the inspiral veto fAmpMatchIN will change, and we need the original here. */
-    double df = pAmp->fAmpMatchIM - pAmp->fAmpMatchIN;
-    pAmp->CollocationPointsFreqsAmplitudeInter[0] =  pAmp->fAmpMatchIN + df/3. ;
-    pAmp->CollocationPointsFreqsAmplitudeInter[1] =  pAmp->fAmpMatchIN + df*2./3.;
+        #if DEBUG == 1
+        printf("\n\n*** IMRPhenomXHM_GetAmplitudeCoefficients ***\n\n");
+        printf("fring_%i = %.16f\n", pWFHM->modeTag, pWFHM->fRING);
+        printf("fdamp_%i = %.16f\n", pWFHM->modeTag, pWFHM->fDAMP);
+        printf("fcutInsp_%i = %.16f \n", pWFHM->modeTag, pAmp->fAmpMatchIN);
+        printf("fcutRD_%i   = %.16f \n", pWFHM->modeTag, pAmp->fAmpMatchIM);
+        #endif
 
-    int nCollocPtsInspAmp  = pWFHM->nCollocPtsInspAmp;
-    int nCollocPtsInterAmp = pWFHM->nCollocPtsInterAmp;
+        /* Compute the frequencies for Intermediate collocation points. */
+        /* It is done now because with the inspiral veto fAmpMatchIN will change, and we need the original here. */
+        double df = pAmp->fAmpMatchIM - pAmp->fAmpMatchIN;
+        pAmp->CollocationPointsFreqsAmplitudeInter[0] =  pAmp->fAmpMatchIN + df/3. ;
+        pAmp->CollocationPointsFreqsAmplitudeInter[1] =  pAmp->fAmpMatchIN + df*2./3.;
 
-    int modeint = pWFHM->modeInt;
+        int nCollocPtsInspAmp  = pWFHM->nCollocPtsInspAmp;
+        int nCollocPtsInterAmp = pWFHM->nCollocPtsInterAmp;
 
-    #if DEBUG == 1
-    printf("nCollocPtsInspAmp  = %i \n",nCollocPtsInspAmp);
-    printf("nCollocPtsInterAmp = %i \n",nCollocPtsInterAmp);
-    #endif
+        int modeint = pWFHM->modeInt;
 
+        #if DEBUG == 1
+        printf("nCollocPtsInspAmp  = %i \n",nCollocPtsInspAmp);
+        printf("nCollocPtsInterAmp = %i \n",nCollocPtsInterAmp);
+        #endif
 
-    /*** Proceed region by region ***/
+        /*****************/
+        /*    INSPIRAL   */
+        /*****************/
 
-    /*****************/
-    /*    INSPIRAL   */
-    /*****************/
-    #if DEBUG == 1
-    printf("\n**** INSPIRAL ****\n\n");
-    printf("IMRPhenomXHMInspiralAmpVersion = %i\r\n",pWFHM->IMRPhenomXHMInspiralAmpVersion);
-    #endif
+        #if DEBUG == 1
+        printf("\n**** INSPIRAL ****\n\n");
+        printf("IMRPhenomXHMInspiralAmpVersion = %i\r\n",pWFHM->IMRPhenomXHMInspiralAmpVersion);
+        #endif
 
-    /* Take Frequency Domain Post-Newtonian Amplitude Coefficients */
-    IMRPhenomXHM_GetPNAmplitudeCoefficients(pAmp, pWFHM, pWF22);
+        /* Take Frequency Domain Post-Newtonian Amplitude Coefficients */
+        IMRPhenomXHM_GetPNAmplitudeCoefficients(pAmp, pWFHM, pWF22);
 
-    #if DEBUG == 1
-    printf("PN coeff %.16f   %.16f\n", creal(pAmp->pnInitial),cimag(pAmp->pnInitial));
-    printf("PN coeff %.16f   %.16f\n", creal(pAmp->pnOneThird),cimag(pAmp->pnOneThird));
-    printf("PN coeff %.16f   %.16f\n", creal(pAmp->pnTwoThirds),cimag(pAmp->pnTwoThirds));
-    printf("PN coeff %.16f   %.16f\n", creal(pAmp->pnThreeThirds),cimag(pAmp->pnThreeThirds));
-    printf("PN coeff %.16f   %.16f\n", creal(pAmp->pnFourThirds),cimag(pAmp->pnFourThirds));
-    printf("PN coeff %.16f   %.16f\n", creal(pAmp->pnFiveThirds),cimag(pAmp->pnFiveThirds));
-    printf("PN coeff %.16f   %.16f\n", creal(pAmp->pnSixThirds),cimag(pAmp->pnSixThirds));
-    #endif
+        #if DEBUG == 1
+        printf("PN coeff %.16f   %.16f\n", creal(pAmp->pnInitial),cimag(pAmp->pnInitial));
+        printf("PN coeff %.16f   %.16f\n", creal(pAmp->pnOneThird),cimag(pAmp->pnOneThird));
+        printf("PN coeff %.16f   %.16f\n", creal(pAmp->pnTwoThirds),cimag(pAmp->pnTwoThirds));
+        printf("PN coeff %.16f   %.16f\n", creal(pAmp->pnThreeThirds),cimag(pAmp->pnThreeThirds));
+        printf("PN coeff %.16f   %.16f\n", creal(pAmp->pnFourThirds),cimag(pAmp->pnFourThirds));
+        printf("PN coeff %.16f   %.16f\n", creal(pAmp->pnFiveThirds),cimag(pAmp->pnFiveThirds));
+        printf("PN coeff %.16f   %.16f\n", creal(pAmp->pnSixThirds),cimag(pAmp->pnSixThirds));
+        #endif
 
-    // Initialize frequencies of colloc points   !!!! ASSUMING YOU HAVE 3 COLLOC POINTS
-    pAmp->CollocationPointsFreqsAmplitudeInsp[0] = 1.0  * pAmp->fAmpMatchIN;
-    pAmp->CollocationPointsFreqsAmplitudeInsp[1] = 0.75 * pAmp->fAmpMatchIN;
-    pAmp->CollocationPointsFreqsAmplitudeInsp[2] = 0.5  * pAmp->fAmpMatchIN;
-
-    double fcutInsp, f1, f2, f3;
-    fcutInsp = pAmp->fAmpMatchIN;                      // Matching frequency between inspiral and intermediate
-    f1 = pAmp->CollocationPointsFreqsAmplitudeInsp[0]; // Frequency of colloc point 1 = 1.*fcutInsp
-    f2 = pAmp->CollocationPointsFreqsAmplitudeInsp[1]; // Frequency of colloc point 2 = 0.75*fcutInsp
-    f3 = pAmp->CollocationPointsFreqsAmplitudeInsp[2]; // Frequency of colloc point 3 = 0.5*fcutInsp
-
-    // Compute the useful powers of fcutInsp, f1, f2, f3. Remembers: f3 < f2 < f1 = fcutInsp.
-    IMRPhenomX_UsefulPowers powers_of_fcutInsp, powers_of_f1, powers_of_f2, powers_of_f3;
-    IMRPhenomX_Initialize_Powers(&powers_of_fcutInsp, fcutInsp);  // fcutInsp and f1 are the same but we keep them separated if in the future we change the frequencies of the collocatio points.
-    IMRPhenomX_Initialize_Powers(&powers_of_f1, f1);
-    IMRPhenomX_Initialize_Powers(&powers_of_f2, f2);
-    IMRPhenomX_Initialize_Powers(&powers_of_f3, f3);
-
-    // Compute the values of Post-Newtoninan ansatz (without the pseudo-PN terms) at the frequencies of the collocation points.
-    double PNf1, PNf2, PNf3;
-    PNf1 = IMRPhenomXHM_Inspiral_PNAmp_Ansatz(&powers_of_f1, pWFHM, pAmp);
-    PNf2 = IMRPhenomXHM_Inspiral_PNAmp_Ansatz(&powers_of_f2, pWFHM, pAmp);
-    PNf3 = IMRPhenomXHM_Inspiral_PNAmp_Ansatz(&powers_of_f3, pWFHM, pAmp);
-
-    pAmp->PNAmplitudeInsp[0] = PNf1;
-    pAmp->PNAmplitudeInsp[1] = PNf2;
-    pAmp->PNAmplitudeInsp[2] = PNf3;
-
-    // Initialize values of collocation points at the previous 3 frequencies. They are taken from the parameter space fits.
-    for(int i = 0; i<nCollocPtsInspAmp; i++)
-    {
-      pAmp->CollocationPointsValuesAmplitudeInsp[i] = fabs(pAmp->InspiralAmpFits[modeint*nCollocPtsInspAmp+i](pWF22->eta,pWF22->chiPNHat,pWF22->chi1L,pWF22->chi2L,pWFHM->IMRPhenomXHMInspiralAmpFitsVersion));
-    }
+        // Initialize frequencies of colloc points   !!!! ASSUMING YOU HAVE 3 COLLOC POINTS
+        pAmp->CollocationPointsFreqsAmplitudeInsp[0] = 1.0  * pAmp->fAmpMatchIN;
+        pAmp->CollocationPointsFreqsAmplitudeInsp[1] = 0.75 * pAmp->fAmpMatchIN;
+        pAmp->CollocationPointsFreqsAmplitudeInsp[2] = 0.5  * pAmp->fAmpMatchIN;
+
+        double fcutInsp, f1, f2, f3;
+        fcutInsp = pAmp->fAmpMatchIN;                      // Matching frequency between inspiral and intermediate
+        f1 = pAmp->CollocationPointsFreqsAmplitudeInsp[0]; // Frequency of colloc point 1 = 1.*fcutInsp
+        f2 = pAmp->CollocationPointsFreqsAmplitudeInsp[1]; // Frequency of colloc point 2 = 0.75*fcutInsp
+        f3 = pAmp->CollocationPointsFreqsAmplitudeInsp[2]; // Frequency of colloc point 3 = 0.5*fcutInsp
+
+        // Compute the useful powers of fcutInsp, f1, f2, f3. Remembers: f3 < f2 < f1 = fcutInsp.
+        IMRPhenomX_UsefulPowers powers_of_fcutInsp, powers_of_f1, powers_of_f2, powers_of_f3;
+        IMRPhenomX_Initialize_Powers(&powers_of_fcutInsp, fcutInsp);  // fcutInsp and f1 are the same but we keep them separated if in the future we change the frequencies of the collocatio points.
+        IMRPhenomX_Initialize_Powers(&powers_of_f1, f1);
+        IMRPhenomX_Initialize_Powers(&powers_of_f2, f2);
+        IMRPhenomX_Initialize_Powers(&powers_of_f3, f3);
+
+        // Compute the values of Post-Newtoninan ansatz (without the pseudo-PN terms) at the frequencies of the collocation points.
+        double PNf1, PNf2, PNf3;
+        PNf1 = IMRPhenomXHM_Inspiral_PNAmp_Ansatz(&powers_of_f1, pWFHM, pAmp);
+        PNf2 = IMRPhenomXHM_Inspiral_PNAmp_Ansatz(&powers_of_f2, pWFHM, pAmp);
+        PNf3 = IMRPhenomXHM_Inspiral_PNAmp_Ansatz(&powers_of_f3, pWFHM, pAmp);
+
+        pAmp->PNAmplitudeInsp[0] = PNf1;
+        pAmp->PNAmplitudeInsp[1] = PNf2;
+        pAmp->PNAmplitudeInsp[2] = PNf3;
+
+        // Initialize values of collocation points at the previous 3 frequencies. They are taken from the parameter space fits.
+        for(int i = 0; i<nCollocPtsInspAmp; i++)
+        {
+          pAmp->CollocationPointsValuesAmplitudeInsp[i] = fabs(pAmp->InspiralAmpFits[modeint*nCollocPtsInspAmp+i](pWF22,pWFHM->IMRPhenomXHMInspiralAmpFitsVersion));
+        }
+    
 
-    // Values of the collocation point minus the Post-Newtonian value. This gives a "collocation point" for the pseudo-PN part.
-    // This way is more convenient becuase the reconstuction does not depended on the PN ansatz used.
-    REAL8 iv1, iv2, iv3;
-    iv1 = pAmp->CollocationPointsValuesAmplitudeInsp[0] - PNf1;
-    iv2 = pAmp->CollocationPointsValuesAmplitudeInsp[1] - PNf2;
-    iv3 = pAmp->CollocationPointsValuesAmplitudeInsp[2] - PNf3;
 
+        // Values of the collocation point minus the Post-Newtonian value. This gives a "collocation point" for the pseudo-PN part.
+        // This way is more convenient becuase the reconstuction does not depended on the PN ansatz used.
+        REAL8 iv1, iv2, iv3;
+        iv1 = pAmp->CollocationPointsValuesAmplitudeInsp[0] - PNf1;
+        iv2 = pAmp->CollocationPointsValuesAmplitudeInsp[1] - PNf2;
+        iv3 = pAmp->CollocationPointsValuesAmplitudeInsp[2] - PNf3;
 
-    #if DEBUG == 1
-    printf("\nAmplitude pseudo collocation points before veto\n");
-    printf("fAmpMatchIN = %.16f\n",pAmp->fAmpMatchIN);
-    printf("F1   = %.16f\n", f1);
-    printf("F2   = %.16f\n", f2);
-    printf("F3   = %.16f\n\n", f3);
-    printf("I1   = %.16f\n", pAmp->CollocationPointsValuesAmplitudeInsp[0]);
-    printf("I2   = %.16f\n", pAmp->CollocationPointsValuesAmplitudeInsp[1]);
-    printf("I3   = %.16f\n\n", pAmp->CollocationPointsValuesAmplitudeInsp[2]);
-    printf("PNf1 = %.16f\n", PNf1);
-    printf("PNf2 = %.16f\n", PNf2);
-    printf("PNf3 = %.16f\n\n", PNf3);
-    REAL8 piv1, piv2, piv3;
-    piv1 = pAmp->CollocationPointsValuesAmplitudeInsp[0]*pWF22->ampNorm*powers_of_f1.m_seven_sixths;
-    piv2 = pAmp->CollocationPointsValuesAmplitudeInsp[1]*pWF22->ampNorm*powers_of_f2.m_seven_sixths;
-    piv3 = pAmp->CollocationPointsValuesAmplitudeInsp[2]*pWF22->ampNorm*powers_of_f3.m_seven_sixths;
-    printf("p1   = %.16f\n", piv1);
-    printf("p2   = %.16f\n", piv2);
-    printf("p3   = %.16f\n\n", piv3);
-    printf("V1   = %.16f\n", iv1);
-    printf("V2   = %.16f\n", iv2);
-    printf("V3   = %.16f\n\n", iv3);
-    #endif
 
-    /*
-       VETO: Choose the collocations points to use.
-       Outside of the callibration region the collocation points can have a wavy behaviour so we remove some of them.
-    */
-    if(pWFHM->InspiralAmpVeto == 1){
-      IMRPhenomXHM_Inspiral_Amplitude_Veto(&iv1, &iv2, &iv3, &powers_of_f1, &powers_of_f2, &powers_of_f3, pAmp, pWFHM);
-    }
-    #if DEBUG == 1
-    printf("\nInspiral Veto: AmpVersion = %i",pWFHM->IMRPhenomXHMInspiralAmpVersion);
-    #endif
-    /* The 32 mode in this corner of the parameter space always uses the PN only */
-    if(pWFHM->modeTag==32 && pWF22->q>2.5 && pWF22->chi1L<-0.9 && pWF22->chi2L<-0.9) pWFHM->IMRPhenomXHMInspiralAmpVersion = 0;
-    /* The 32 mode in this corner of the parameter space removes the last collocation point */
-    if(pWFHM->modeTag==32 && pWF22->q>2.5 && pWF22->chi1L<-0.6 && pWF22->chi2L>0. && iv1!=0){
-      pWFHM->IMRPhenomXHMInspiralAmpVersion = pWFHM->IMRPhenomXHMInspiralAmpVersion - 1;
-      iv1 = 0.;
-    }
-    /* The 33 mode in this corner of the parameter space removes the last collocation point */
-    if(pWFHM->modeTag==33 && (1.2>pWF22->q && pWF22->q>1. && pWF22->chi1L<-0.1 && pWF22->chi2L>0. && iv1!=0)){//November
-      pWFHM->IMRPhenomXHMInspiralAmpVersion = pWFHM->IMRPhenomXHMInspiralAmpVersion - 1;
-      iv1 = 0.;
-    }
-    #if DEBUG == 1
-    printf("\nInspiral Veto: AmpVersion = %i", pWFHM->IMRPhenomXHMInspiralAmpVersion);
-    #endif
-    //********* Remember that f3 < f2 < f1 !!!!! *****************
-    /* Check for wavy collocation points. Only when we have 3 coll points. */
-    if(pWFHM->IMRPhenomXHMInspiralAmpVersion == 3 && pAmp->WavyInsp == 1){
-        if(WavyPoints(pAmp->CollocationPointsValuesAmplitudeInsp[0]*powers_of_f1.m_seven_sixths,pAmp->CollocationPointsValuesAmplitudeInsp[1]*powers_of_f2.m_seven_sixths,pAmp->CollocationPointsValuesAmplitudeInsp[2]*powers_of_f3.m_seven_sixths)==1){
-           iv2 = 0;
-           #if DEBUG == 1
-           printf("\nWavy Inspiral\n");
-           #endif
-           pWFHM->IMRPhenomXHMInspiralAmpVersion = pWFHM->IMRPhenomXHMInspiralAmpVersion - 1;
-         }
-    }
-    #if DEBUG == 1
-    printf("\nInspiral Veto: AmpVersion = %i",pWFHM->IMRPhenomXHMInspiralAmpVersion);
-    printf("\niv1 iv2 iv3 %e %e %e\n", iv1, iv2, iv3);
-    #endif
-    // Rename collocation points and frequencies.
-    if(iv2==0){
-      #if DEBUG == 1
-          printf("\niv2 = 0\n");
-      #endif
-        iv2 = iv3;
-        iv3 = 0.;
-        powers_of_f2 = powers_of_f3;
-    }
-    if(iv1==0){
-      #if DEBUG == 1
-          printf("\niv1 = 0\n");
-      #endif
-        iv1 = iv2;
-        powers_of_f1 = powers_of_f2;
-        powers_of_fcutInsp = powers_of_f1;
-        iv2 = iv3;
-        iv3 = 0.;
-        powers_of_f2 = powers_of_f3;
-    }
-    if(pWFHM->IMRPhenomXHMInspiralAmpVersion == 0)  // when using PN we take fcutInsp = fMECO_lm
-    {
-      IMRPhenomX_Initialize_Powers(&powers_of_fcutInsp, (pWFHM->fMECOlm));
-    }
+        #if DEBUG == 1
+        printf("\nAmplitude pseudo collocation points before veto\n");
+        printf("fAmpMatchIN = %.16f\n",pAmp->fAmpMatchIN);
+        printf("F1   = %.16f\n", f1);
+        printf("F2   = %.16f\n", f2);
+        printf("F3   = %.16f\n\n", f3);
+        printf("I1   = %.16f\n", pAmp->CollocationPointsValuesAmplitudeInsp[0]);
+        printf("I2   = %.16f\n", pAmp->CollocationPointsValuesAmplitudeInsp[1]);
+        printf("I3   = %.16f\n\n", pAmp->CollocationPointsValuesAmplitudeInsp[2]);
+        printf("PNf1 = %.16f\n", PNf1);
+        printf("PNf2 = %.16f\n", PNf2);
+        printf("PNf3 = %.16f\n\n", PNf3);
+        REAL8 piv1, piv2, piv3;
+        piv1 = pAmp->CollocationPointsValuesAmplitudeInsp[0]*pWF22->ampNorm*powers_of_f1.m_seven_sixths;
+        piv2 = pAmp->CollocationPointsValuesAmplitudeInsp[1]*pWF22->ampNorm*powers_of_f2.m_seven_sixths;
+        piv3 = pAmp->CollocationPointsValuesAmplitudeInsp[2]*pWF22->ampNorm*powers_of_f3.m_seven_sixths;
+        printf("p1   = %.16f\n", piv1);
+        printf("p2   = %.16f\n", piv2);
+        printf("p3   = %.16f\n\n", piv3);
+        printf("V1   = %.16f\n", iv1);
+        printf("V2   = %.16f\n", iv2);
+        printf("V3   = %.16f\n\n", iv3);
+        #endif
 
-    // Update the Inspiral cutting frequency to the last collocation point alive.
-    pAmp->fAmpMatchIN = powers_of_fcutInsp.itself;
-    // End of VETO
+        /*
+           VETO: Choose the collocations points to use.
+           Outside of the callibration region the collocation points can have a wavy behaviour so we remove some of them.
+        */
+        if(pWFHM->InspiralAmpVeto == 1){
+          IMRPhenomXHM_Inspiral_Amplitude_Veto(&iv1, &iv2, &iv3, &powers_of_f1, &powers_of_f2, &powers_of_f3, pAmp, pWFHM);
+        }
+        #if DEBUG == 1
+        printf("\nInspiral Veto: AmpVersion = %i",pWFHM->IMRPhenomXHMInspiralAmpVersion);
+        #endif
+        /* The 32 mode in this corner of the parameter space always uses the PN only */
+        if(pWFHM->modeTag==32 && pWF22->q>2.5 && pWF22->chi1L<-0.9 && pWF22->chi2L<-0.9) pWFHM->IMRPhenomXHMInspiralAmpVersion = 0;
+        /* The 32 mode in this corner of the parameter space removes the last collocation point */
+        if(pWFHM->modeTag==32 && pWF22->q>2.5 && pWF22->chi1L<-0.6 && pWF22->chi2L>0. && iv1!=0){
+          pWFHM->IMRPhenomXHMInspiralAmpVersion = pWFHM->IMRPhenomXHMInspiralAmpVersion - 1;
+          iv1 = 0.;
+        }
+        /* The 33 mode in this corner of the parameter space removes the last collocation point */
+        if(pWFHM->modeTag==33 && (1.2>pWF22->q && pWF22->q>1. && pWF22->chi1L<-0.1 && pWF22->chi2L>0. && iv1!=0)){//November
+          pWFHM->IMRPhenomXHMInspiralAmpVersion = pWFHM->IMRPhenomXHMInspiralAmpVersion - 1;
+          iv1 = 0.;
+        }
+        #if DEBUG == 1
+        printf("\nInspiral Veto: AmpVersion = %i", pWFHM->IMRPhenomXHMInspiralAmpVersion);
+        #endif
+        //********* Remember that f3 < f2 < f1 !!!!! *****************
+        /* Check for wavy collocation points. Only when we have 3 coll points. */
+        if(pWFHM->IMRPhenomXHMInspiralAmpVersion == 3 && pAmp->WavyInsp == 1){
+            if(WavyPoints(pAmp->CollocationPointsValuesAmplitudeInsp[0]*powers_of_f1.m_seven_sixths,pAmp->CollocationPointsValuesAmplitudeInsp[1]*powers_of_f2.m_seven_sixths,pAmp->CollocationPointsValuesAmplitudeInsp[2]*powers_of_f3.m_seven_sixths)==1){
+               iv2 = 0;
+               #if DEBUG == 1
+               printf("\nWavy Inspiral\n");
+               #endif
+               pWFHM->IMRPhenomXHMInspiralAmpVersion = pWFHM->IMRPhenomXHMInspiralAmpVersion - 1;
+             }
+        }
+        #if DEBUG == 1
+        printf("\nInspiral Veto: AmpVersion = %i",pWFHM->IMRPhenomXHMInspiralAmpVersion);
+        printf("\niv1 iv2 iv3 %e %e %e\n", iv1, iv2, iv3);
+        #endif
+        // Rename collocation points and frequencies.
+        if(iv2==0){
+          #if DEBUG == 1
+              printf("\niv2 = 0\n");
+          #endif
+            iv2 = iv3;
+            iv3 = 0.;
+            powers_of_f2 = powers_of_f3;
+        }
+        if(iv1==0){
+          #if DEBUG == 1
+              printf("\niv1 = 0\n");
+          #endif
+            iv1 = iv2;
+            powers_of_f1 = powers_of_f2;
+            powers_of_fcutInsp = powers_of_f1;
+            iv2 = iv3;
+            iv3 = 0.;
+            powers_of_f2 = powers_of_f3;
+        }
+        if(pWFHM->IMRPhenomXHMInspiralAmpVersion == 0)  // when using PN we take fcutInsp = fMECO_lm
+        {
+          IMRPhenomX_Initialize_Powers(&powers_of_fcutInsp, (pWFHM->fMECOlm));
+        }
 
+        // Update the Inspiral cutting frequency to the last collocation point alive.
+        pAmp->fAmpMatchIN = powers_of_fcutInsp.itself;
+        // End of VETO
 
-    #if DEBUG == 1
-    printf("\nAmplitude pseudo collocation points after veto\n");
-    printf("fAmpMatchIN = %.16f\n", pAmp->fAmpMatchIN);
-    printf("F1   = %.16f\n", powers_of_f1.itself);
-    printf("F2   = %.16f\n", powers_of_f2.itself);
-    printf("F3   = %.16f\n", powers_of_f3.itself);
-    printf("V1   = %.16f\n", iv1);
-    printf("V2   = %.16f\n", iv2);
-    printf("V3   = %.16f\n", iv3);
-    #endif
 
-    /* Get the pseudo-PN coefficients. */
-    /* The whole inspiral ansatz is given by PNAnsatz(f) + pseudo-PN(f),  with pseudo-PN(f) = rho1 *(f/fcutInsp)^(7/3) + rho2(f/fcutInsp)^(8/3) + rho3(f/fcutInsp)^(9/3).
-    The coefficients are computed demanding that the pseudo-PN part at the three collocation points frequencies returns the actual collocation points: iv1, iv2, iv3.   */
-    pAmp->rho1 = IMRPhenomXHM_Inspiral_Amp_rho1(iv1, iv2, iv3, &powers_of_fcutInsp, &powers_of_f1, &powers_of_f2, &powers_of_f3, pWFHM);
-    pAmp->rho2 = IMRPhenomXHM_Inspiral_Amp_rho2(iv1, iv2, iv3, &powers_of_fcutInsp, &powers_of_f1, &powers_of_f2, &powers_of_f3, pWFHM);
-    pAmp->rho3 = IMRPhenomXHM_Inspiral_Amp_rho3(iv1, iv2, iv3, &powers_of_fcutInsp, &powers_of_f1, &powers_of_f2, &powers_of_f3, pWFHM);
+        #if DEBUG == 1
+        printf("\nAmplitude pseudo collocation points after veto\n");
+        printf("fAmpMatchIN = %.16f\n", pAmp->fAmpMatchIN);
+        printf("F1   = %.16f\n", powers_of_f1.itself);
+        printf("F2   = %.16f\n", powers_of_f2.itself);
+        printf("F3   = %.16f\n", powers_of_f3.itself);
+        printf("V1   = %.16f\n", iv1);
+        printf("V2   = %.16f\n", iv2);
+        printf("V3   = %.16f\n", iv3);
+        #endif
 
-    #if DEBUG == 1
-    printf("\nAmplitude pseudo PN coeffcients after veto\n");
-    printf("rho1 = %.16f\n",pAmp->rho1);
-    printf("rho2 = %.16f\n",pAmp->rho2);
-    printf("rho3 = %.16f\n",pAmp->rho3);
-    #endif
+        /* Get the pseudo-PN coefficients. */
+        /* The whole inspiral ansatz is given by PNAnsatz(f) + pseudo-PN(f),  with pseudo-PN(f) = rho1 *(f/fcutInsp)^(7/3) + rho2(f/fcutInsp)^(8/3) + rho3(f/fcutInsp)^(9/3).
+        The coefficients are computed demanding that the pseudo-PN part at the three collocation points frequencies returns the actual collocation points: iv1, iv2, iv3.   */
+        pAmp->rho1 = IMRPhenomXHM_Inspiral_Amp_rho1(iv1, iv2, iv3, &powers_of_fcutInsp, &powers_of_f1, &powers_of_f2, &powers_of_f3, pWFHM);
+        pAmp->rho2 = IMRPhenomXHM_Inspiral_Amp_rho2(iv1, iv2, iv3, &powers_of_fcutInsp, &powers_of_f1, &powers_of_f2, &powers_of_f3, pWFHM);
+        pAmp->rho3 = IMRPhenomXHM_Inspiral_Amp_rho3(iv1, iv2, iv3, &powers_of_fcutInsp, &powers_of_f1, &powers_of_f2, &powers_of_f3, pWFHM);
 
-    // To avoid passing an extra argument to IMRPhenomXHM_Inspiral_Amp_Ansatz we store this powers in pAmp.
-    pAmp->fcutInsp_seven_thirds = powers_of_fcutInsp.seven_thirds;
-    pAmp->fcutInsp_eight_thirds = powers_of_fcutInsp.eight_thirds;
-    pAmp->fcutInsp_three = powers_of_fcutInsp.three;
+        #if DEBUG == 1
+        printf("\nAmplitude pseudo PN coeffcients after veto\n");
+        printf("rho1 = %.16f\n",pAmp->rho1);
+        printf("rho2 = %.16f\n",pAmp->rho2);
+        printf("rho3 = %.16f\n",pAmp->rho3);
+        #endif
 
+        // To avoid passing an extra argument to IMRPhenomXHM_Inspiral_Amp_Ansatz we store this powers in pAmp.
+        pAmp->fcutInsp_seven_thirds = powers_of_fcutInsp.seven_thirds;
+        pAmp->fcutInsp_eight_thirds = powers_of_fcutInsp.eight_thirds;
+        pAmp->fcutInsp_three = powers_of_fcutInsp.three;
 
-    /*****************/
-    /*    RINGDOWN   */
-    /*****************/
-    #if DEBUG == 1
-    printf("\n\n**** RINGDOWN ****\n\n");
-    #endif
 
-    // We have three "fitted" coefficients across parameter space: alambda, lambda and sigma. Sigma will be constat for all the modes except the 21.
-    pAmp->alambda = fabs(pAmp->RingdownAmpFits[modeint*3](pWF22->eta,pWF22->STotR,pWF22->chi1L,pWF22->chi2L,pWFHM->IMRPhenomXHMRingdownAmpFitsVersion));
-    pAmp->lambda  = pAmp->RingdownAmpFits[modeint*3+1](pWF22->eta,pWF22->STotR,pWF22->chi1L,pWF22->chi2L,pWFHM->IMRPhenomXHMRingdownAmpFitsVersion);
-    pAmp->sigma   = pAmp->RingdownAmpFits[modeint*3+2](pWF22->eta,pWF22->STotR,pWF22->chi1L,pWF22->chi2L,pWFHM->IMRPhenomXHMRingdownAmpFitsVersion);
-    pAmp->lc      = 1./12.;
+        /*****************/
+        /*    RINGDOWN   */
+        /*****************/
+        #if DEBUG == 1
+        printf("\n\n**** RINGDOWN ****\n\n");
+        #endif
 
-    #if DEBUG == 1
-    printf("\nuseInspAnsatzRigndown = %i\n",pAmp->useInspAnsatzRingdown);
-    printf("alambda = %.16f\r\n",pAmp->alambda);
-    #endif
+        // We have three "fitted" coefficients across parameter space: alambda, lambda and sigma (RDCoefficients[0,1,2]). Sigma will be constat for all the modes except the 21.
+        pAmp->RDCoefficient[0] = fabs(pAmp->RingdownAmpFits[modeint*3](pWF22,pWFHM->IMRPhenomXHMRingdownAmpFitsVersion));
+        pAmp->RDCoefficient[1] = pAmp->RingdownAmpFits[modeint*3+1](pWF22,pWFHM->IMRPhenomXHMRingdownAmpFitsVersion);
+        pAmp->RDCoefficient[2] = pAmp->RingdownAmpFits[modeint*3+2](pWF22,pWFHM->IMRPhenomXHMRingdownAmpFitsVersion);
+        pAmp->RDCoefficient[3] = 1./12.;
 
-    // For some cases with extreme spins there is almost no merger and the transition to the ringdown is very sharp.
-    // The coefficients of the ringdown do not work well here and we take an approximation of the inspiral.
-    if(pAmp->useInspAnsatzRingdown==1){
-      // The Ringdown amp at fAmpMatchIM is set to be 0.9 the amplitude in the last inspiral collocation point
-      pAmp->alambda = 0.9*fabs(IMRPhenomXHM_Inspiral_Amp_Ansatz(&powers_of_fcutInsp, pWFHM, pAmp)/(IMRPhenomXHM_RD_Amp_Ansatz(pAmp->fAmpMatchIM, pWFHM, pAmp)/pAmp->alambda));
-    }
+        #if DEBUG == 1
+        printf("\nuseInspAnsatzRigndown = %i\n",pAmp->useInspAnsatzRingdown);
+        printf("alambda = %.16f\r\n",pAmp->RDCoefficient[0]);
+        #endif
 
-    #if DEBUG == 1
-    printf("alambda = %.16f\r\n",pAmp->alambda);
-    printf("lambda  = %.16f\r\n",pAmp->lambda);
-    printf("sigma   = %.16f\r\n",pAmp->sigma);
-    printf("lc      = %.16f\r\n",pAmp->lc);
-    #endif
+        // For some cases with extreme spins there is almost no merger and the transition to the ringdown is very sharp.
+        // The coefficients of the ringdown do not work well here and we take an approximation of the inspiral.
+        if(pAmp->useInspAnsatzRingdown==1){
+          // The Ringdown amp at fAmpMatchIM is set to be 0.9 the amplitude in the last inspiral collocation point
+          IMRPhenomX_UsefulPowers powers_of_fRD;
+          IMRPhenomX_Initialize_Powers(&powers_of_fRD, pAmp->fAmpMatchIM);
+          pAmp->RDCoefficient[0] = 0.9*fabs(IMRPhenomXHM_Inspiral_Amp_Ansatz(&powers_of_fcutInsp, pWFHM, pAmp)/(IMRPhenomXHM_RD_Amp_Ansatz(&powers_of_fRD, pWFHM, pAmp)/pAmp->RDCoefficient[0]));
+        }
 
+        #if DEBUG == 1
+        printf("alambda = %.16f\r\n",pAmp->RDCoefficient[0]);
+        printf("lambda  = %.16f\r\n",pAmp->RDCoefficient[1]);
+        printf("sigma   = %.16f\r\n",pAmp->RDCoefficient[2]);
+        printf("lc      = %.16f\r\n",pAmp->RDCoefficient[3]);
+        #endif
 
-    /*******************/
-    /*   INTERMEDIATE  */
-    /*******************/
-    #if DEBUG == 1
-    printf("\n\n**** INTERMEDIATE ****\n\n");
-    #endif
 
-    // Initialize values of collocation points. They are taken from the parameter space fits.
-    for(int i = 0; i<nCollocPtsInterAmp; i++)
-    {
-      pAmp->CollocationPointsValuesAmplitudeInter[i] = fabs(pAmp->IntermediateAmpFits[modeint*nCollocPtsInterAmp+i](pWF22->eta,pWF22->STotR,pWF22->chi1L,pWF22->chi2L,pWFHM->IMRPhenomXHMIntermediateAmpFitsVersion));
-    }
+        /*******************/
+        /*   INTERMEDIATE  */
+        /*******************/
 
-    /* For reconstructing the intermediate region we need value and derivative at the beginning and at the end of the intermediate region, given by the inspiral and ringdown ansatzs.
-    And also the two values at the two intermediate collocation points. This gives 6 parameters, that will determine the 6 coefficients of the inverse of the 5th order polynomial
-    that we use for reconstruction.
-    This is the default behaviour, however the veto conditions can reduce the order of the polynomial.
-    */
+        #if DEBUG == 1
+        printf("\n\n**** INTERMEDIATE ****\n\n");
+        #endif
 
-    double F1, F2, F3, F4;  //Frequencies of the collocation points in the intermediate region
-    F1     = powers_of_fcutInsp.itself;
-    F2     = pAmp->CollocationPointsFreqsAmplitudeInter[0];
-    F3     = pAmp->CollocationPointsFreqsAmplitudeInter[1];
-    F4     = pAmp->fAmpMatchIM;
+        // Initialize values of collocation points. They are taken from the parameter space fits.
+        for(int i = 0; i<nCollocPtsInterAmp; i++)
+        {
+          pAmp->CollocationPointsValuesAmplitudeInter[i] = fabs(pAmp->IntermediateAmpFits[modeint*nCollocPtsInterAmp+i](pWF22,pWFHM->IMRPhenomXHMIntermediateAmpFitsVersion));
+        }
 
-    #if DEBUG == 1
-    printf("F1 = %.16f\n",F1);
-    printf("F2 = %.16f\n",F2);
-    printf("F3 = %.16f\n",F3);
-    printf("F4 = %.16f\n\n",F4);
-    #endif
+        /* For reconstructing the intermediate region we need value and derivative at the beginning and at the end of the intermediate region, given by the inspiral and ringdown ansatzs.
+        And also the two values at the two intermediate collocation points. This gives 6 parameters, that will determine the 6 coefficients of the inverse of the 5th order polynomial
+        that we use for reconstruction.
+        This is the default behaviour, however the veto conditions can reduce the order of the polynomial.
+        */
 
-    // Initialize useful powers.
-    IMRPhenomX_UsefulPowers powers_of_F1;
-    IMRPhenomX_Initialize_Powers(&powers_of_F1,F1);
-    IMRPhenomX_UsefulPowers powers_of_F4;
-    IMRPhenomX_Initialize_Powers(&powers_of_F4,F4);
-
-    // Compute values at the boundaries (rescaled ansatz with the leading order of the 22).
-    double inspF1 = IMRPhenomXHM_Inspiral_Amp_Ansatz(&powers_of_F1, pWFHM, pAmp);
-    double rdF4;
-    if (pWFHM->MixingOn == 1){
-      rdF4 = cabs(SpheroidalToSpherical(F4, &powers_of_F4, pAmp22, pPhase22, pAmp, pPhase, pWFHM, pWF22));
-    }else{
-      rdF4 = IMRPhenomXHM_RD_Amp_Ansatz(F4, pWFHM, pAmp);
-    };
-
-    // Compute derivatives at the boundaries (rescaled ansatz with the leading order of the 22).
-    double d1, d4;
-    d1     = IMRPhenomXHM_Inspiral_Amp_NDAnsatz(&powers_of_F1,pWFHM,pAmp);
-    if(pWFHM->MixingOn==1){
-      d4 = IMRPhenomXHM_RD_Amp_NDAnsatz(F4, pAmp, pPhase, pWFHM, pAmp22, pPhase22, pWF22);
-    }else{
-      d4 = IMRPhenomXHM_RD_Amp_DAnsatz(F4, pWFHM, pAmp);
-    }
+        double F1, F2, F3, F4;  //Frequencies of the collocation points in the intermediate region
+        F1     = powers_of_fcutInsp.itself;
+        F2     = pAmp->CollocationPointsFreqsAmplitudeInter[0];
+        F3     = pAmp->CollocationPointsFreqsAmplitudeInter[1];
+        F4     = pAmp->fAmpMatchIM;
 
-    #if DEBUG == 1
-    printf("d1 = %.16f\n",d1);
-    printf("d4 = %.16f\n",d4);
-    #endif
+        #if DEBUG == 1
+        printf("F1 = %.16f\n",F1);
+        printf("F2 = %.16f\n",F2);
+        printf("F3 = %.16f\n",F3);
+        printf("F4 = %.16f\n\n",F4);
+        #endif
 
-    // Derivatives at the boundaries of the whole ansatz.
-    d1     = ((7.0/6.0) * pow(F1,1.0/6.0) / inspF1) - ( pow(F1,7.0/6.0) * d1 / (inspF1*inspF1) );
-    d4     = ((7.0/6.0) * pow(F4,1.0/6.0) / rdF4)   - ( pow(F4,7.0/6.0) * d4 / (rdF4*rdF4) );
+        // Initialize useful powers.
+        IMRPhenomX_UsefulPowers powers_of_F1;
+        IMRPhenomX_Initialize_Powers(&powers_of_F1,F1);
+        IMRPhenomX_UsefulPowers powers_of_F4;
+        IMRPhenomX_Initialize_Powers(&powers_of_F4,F4);
+
+        // Compute values at the boundaries (rescaled ansatz with the leading order of the 22).
+        double inspF1 = IMRPhenomXHM_Inspiral_Amp_Ansatz(&powers_of_F1, pWFHM, pAmp);
+        double rdF4;
+        if (pWFHM->MixingOn == 1){
+          rdF4 = cabs(SpheroidalToSpherical(&powers_of_F4, pAmp22, pPhase22, pAmp, pPhase, pWFHM, pWF22));
+        }else{
+          rdF4 = IMRPhenomXHM_RD_Amp_Ansatz(&powers_of_F4, pWFHM, pAmp);
+        }
 
-    #if DEBUG == 1
-    printf("d1 = %.16f\n",d1);
-    printf("d4 = %.16f\n\n",d4);
-    #endif
+        // Compute derivatives at the boundaries (rescaled ansatz with the leading order of the 22).
+        double d1, d4;
+        d1 = IMRPhenomXHM_Inspiral_Amp_NDAnsatz(&powers_of_F1, pWFHM, pAmp);
+        if(pWFHM->MixingOn==1){
+          d4 = IMRPhenomXHM_RD_Amp_NDAnsatz(&powers_of_F4, pAmp, pPhase, pWFHM, pAmp22, pPhase22, pWF22);
+        }else{
+          d4 = IMRPhenomXHM_RD_Amp_DAnsatz(&powers_of_F4, pWFHM, pAmp);
+        }
+        // Next use of Ansatz will be for return the full strain, set correct rescalefactor
+        pAmp->InspRescaleFactor = 0;
+        pAmp->InterRescaleFactor = 0;
+        pAmp->RDRescaleFactor = 0;
 
-    // These values will feed the reconstruction function of the intermediate for getting the coefficients of the polynomial
-    double V1, V2, V3, V4;
+        #if DEBUG == 1
+        printf("d1 = %.16f\n",d1);
+        printf("d4 = %.16f\n",d4);
+        #endif
 
-    pWFHM->IMRPhenomXHMIntermediateAmpVersion = 105; // by default use 5th order polynomial
+        // Derivatives at the boundaries of the whole ansatz.
+        d1 = ((7.0/6.0) * pow(F1,1.0/6.0) / inspF1) - ( pow(F1,7.0/6.0) * d1 / (inspF1*inspF1) );
+        d4 = ((7.0/6.0) * pow(F4,1.0/6.0) / rdF4)   - ( pow(F4,7.0/6.0) * d4 / (rdF4*rdF4) );
 
-    V1 = powers_of_F1.m_seven_sixths * inspF1;
-    V2 = pAmp->CollocationPointsValuesAmplitudeInter[0];
-    V3 = pAmp->CollocationPointsValuesAmplitudeInter[1];
-    V4 = powers_of_F4.m_seven_sixths * rdF4;
+        #if DEBUG == 1
+        printf("d1 = %.16f\n",d1);
+        printf("d4 = %.16f\n\n",d4);
+        #endif
 
-    #if DEBUG == 1
-    printf("Before intermediate veto \n");
-    printf("V1 = %.16f\n",V1);
-    printf("V2 = %.16f\n",V2);
-    printf("V3 = %.16f\n",V3);
-    printf("V4 = %.16f\n",V4);
-    printf("rdF4 = %.16f\n",rdF4);
-    printf("F4.m_seven_sixths = %.16f\n\n",powers_of_F4.m_seven_sixths);
-    #endif
+        // These values will feed the reconstruction function of the intermediate for getting the coefficients of the polynomial
+        double V1, V2, V3, V4;
 
-    // VETO: outside of the calibration region some collocation points are bad behaved. We veto them and change the type of reconstruction now.
+        pWFHM->IMRPhenomXHMIntermediateAmpVersion = 105; // by default use 5th order polynomial
 
-    if(pAmp->useInspAnsatzRingdown==1){
-      //For these extreme cases we do not use intermediate collocation points -> third order polynomial.
-      V2 = 1.;
-      V3 = 1.;
-      pWFHM->IMRPhenomXHMIntermediateAmpVersion = 101; /*Linear reconstruction*/
-      #if DEBUG == 1
-      printf("VETO: useInspAnsatzRingdown\n");
-      printf("V2 = %.16f\n",V2);
-      printf("V3 = %.16f\n",V3);
-      #endif
-    }
+        V1 = powers_of_F1.m_seven_sixths * inspF1;
+        V2 = pAmp->CollocationPointsValuesAmplitudeInter[0];
+        V3 = pAmp->CollocationPointsValuesAmplitudeInter[1];
+        V4 = powers_of_F4.m_seven_sixths * rdF4;
 
-    // The reconstruction function is the inverse of a polynomial. That we demand pass through the points V1, V2, V3, V4 and has the derivatives d1, d4 at the boundaries.
-    // For simplicity we coded the reconstruction of the polynomial (Update_Intermediate_Amplitude_Coefficients), so we have to feed it with inverse values.
-    V1  = 1.0 / V1;
-    V2  = 1.0 / V2;
-    V3  = 1.0 / V3;
-    V4  = 1.0 / V4;
+        #if DEBUG == 1
+        printf("Before intermediate veto \n");
+        printf("V1 = %.16f\n",V1);
+        printf("V2 = %.16f\n",V2);
+        printf("V3 = %.16f\n",V3);
+        printf("V4 = %.16f\n",V4);
+        printf("rdF4 = %.16f\n",rdF4);
+        printf("F4.m_seven_sixths = %.16f\n\n",powers_of_F4.m_seven_sixths);
+        #endif
 
-    #if DEBUG == 1
-    printf("\nAfter Veto and inverse \n");
-    printf("V1 = %.16f\n",V1);
-    printf("V2 = %.16f\n",V2);
-    printf("V3 = %.16f\n",V3);
-    printf("V4 = %.16f\n",V4);
-    printf("IMRPhenomXHMIntermediateAmpVersion = %i \n\n", pWFHM->IMRPhenomXHMIntermediateAmpVersion);
-    #endif
+        // VETO: outside of the calibration region some collocation points are bad behaved. We veto them and change the type of reconstruction now.
+
+        if(pAmp->useInspAnsatzRingdown==1){
+          //For these extreme cases we do not use intermediate collocation points -> third order polynomial.
+          V2 = 1.;
+          V3 = 1.;
+          pWFHM->IMRPhenomXHMIntermediateAmpVersion = 101; /*Linear reconstruction*/
+          #if DEBUG == 1
+          printf("VETO: useInspAnsatzRingdown\n");
+          printf("V2 = %.16f\n",V2);
+          printf("V3 = %.16f\n",V3);
+          #endif
+        }
 
+        // The reconstruction function is the inverse of a polynomial. That we demand pass through the points V1, V2, V3, V4 and has the derivatives d1, d4 at the boundaries.
+        // For simplicity we coded the reconstruction of the polynomial (Update_Intermediate_Amplitude_Coefficients), so we have to feed it with inverse values.
+        V1  = 1.0 / V1;
+        V2  = 1.0 / V2;
+        V3  = 1.0 / V3;
+        V4  = 1.0 / V4;
 
-    /* If the case does not have extreme mass ratio it skips the next block */
+        #if DEBUG == 1
+        printf("\nAfter Veto and inverse \n");
+        printf("V1 = %.16f\n",V1);
+        printf("V2 = %.16f\n",V2);
+        printf("V3 = %.16f\n",V3);
+        printf("V4 = %.16f\n",V4);
+        printf("IMRPhenomXHMIntermediateAmpVersion = %i \n\n", pWFHM->IMRPhenomXHMIntermediateAmpVersion);
+        #endif
 
 
-    /****** JUST EMR cases, 2 INTERMEDIATE REGIONS ******/
+        /* If the case does not have extreme mass ratio it skips the next block */
 
-    /* For EMR cases the amplitude shows a more pronounced drop off at the end of the inspiral.
-    To model this we split the intermediate region in two.
-    We add an extra collocation point between the end of the inspiral and the first intermediate collocation point, F0.
-    From fcutInsp to FO we use a 4th order polynomial, and from F0 to fcutRD we use the usual 5th that is computed after this block. */
 
-    if(pWFHM->AmpEMR==1){
-      #if DEBUG == 1
-      printf("*** TWO INTERMEDIATE REGIONS ***\n\n");
-      #endif
+        /****** JUST EMR cases, 2 INTERMEDIATE REGIONS ******/
 
-      // Here we compute the first intermediate region with the inverse of a 4th polynomial.
-      // For this we use point and derivative at fcutInsp and F0 (4 coefficients) and the value at the first collocation point (F2), with the total of 5 coefficients.
+        /* For EMR cases the amplitude shows a more pronounced drop off at the end of the inspiral.
+        To model this we split the intermediate region in two.
+        We add an extra collocation point between the end of the inspiral and the first intermediate collocation point, F0.
+        From fcutInsp to FO we use a 4th order polynomial, and from F0 to fcutRD we use the usual 5th that is computed after this block. */
 
-      double F0, V0, d0, F0_seven_sixths;  //Frequency, value, derivative and useful power at the extra collocation point for EMR
+        if(pWFHM->AmpEMR==1){
+          #if DEBUG == 1
+          printf("*** TWO INTERMEDIATE REGIONS ***\n\n");
+          #endif
 
-      F0 = F1 + (F2-F1)/3.;
-      pAmp->fAmpMatchInt12 = F0;
+          // Here we compute the first intermediate region with the inverse of a 4th polynomial.
+          // For this we use point and derivative at fcutInsp and F0 (4 coefficients) and the value at the first collocation point (F2), with the total of 5 coefficients.
 
-      // Take the value and derivative from the parameter space fits.
-      V0 = pAmp->IntermediateAmpFits[modeint*nCollocPtsInterAmp+8](pWF22->eta,pWF22->STotR,pWF22->chi1L,pWF22->chi2L,pWFHM->IMRPhenomXHMIntermediateAmpFitsVersion);
-      d0 = pAmp->IntermediateAmpFits[modeint*nCollocPtsInterAmp+9](pWF22->eta,pWF22->STotR,pWF22->chi1L,pWF22->chi2L,pWFHM->IMRPhenomXHMIntermediateAmpFitsVersion);
+          double F0, V0, d0, F0_seven_sixths;  //Frequency, value, derivative and useful power at the extra collocation point for EMR
 
-      #if DEBUG == 1
-      printf("F0 = %.16f\n",F0);
-      printf("V0 = %.16f\n",V0);
-      printf("d0 = %.16f\n",d0);
-      #endif
+          F0 = F1 + (F2-F1)/3.;
+          pAmp->fAmpMatchInt12 = F0;
 
-      F0_seven_sixths = pow(F0,7.0/6.0);
+          // Take the value and derivative from the parameter space fits.
+          V0 = pAmp->IntermediateAmpFits[modeint*nCollocPtsInterAmp+8](pWF22,pWFHM->IMRPhenomXHMIntermediateAmpFitsVersion);
+          d0 = pAmp->IntermediateAmpFits[modeint*nCollocPtsInterAmp+9](pWF22,pWFHM->IMRPhenomXHMIntermediateAmpFitsVersion);
 
-      d0 = ((7.0/6.0) / (V0*F0))   - ( d0 / (V0*V0*F0_seven_sixths) );
-      V0 = 1. / V0;
+          #if DEBUG == 1
+          printf("F0 = %.16f\n",F0);
+          printf("V0 = %.16f\n",V0);
+          printf("d0 = %.16f\n",d0);
+          #endif
 
-      #if DEBUG == 1
-      printf("1/V0 = %.16f\n",V0);
-      printf("1/d0 = %.16f\n",d0);
-      #endif
+          F0_seven_sixths = pow(F0,7.0/6.0);
 
-      // Get the coefficients of the polynomial for the first intermediate region
-      pAmp->alpha0 = IMRPhenomXHM_Intermediate_Amp_delta0(d1,d0,V1,V2,V3,V0,F1,F2,F3,F0,104); //V3 and F3 will not be used when calling with 104
-      pAmp->alpha1 = IMRPhenomXHM_Intermediate_Amp_delta1(d1,d0,V1,V2,V3,V0,F1,F2,F3,F0,104);
-      pAmp->alpha2 = IMRPhenomXHM_Intermediate_Amp_delta2(d1,d0,V1,V2,V3,V0,F1,F2,F3,F0,104);
-      pAmp->alpha3 = IMRPhenomXHM_Intermediate_Amp_delta3(d1,d0,V1,V2,V3,V0,F1,F2,F3,F0,104);
-      pAmp->alpha4 = IMRPhenomXHM_Intermediate_Amp_delta4(d1,d0,V1,V2,V3,V0,F1,F2,F3,F0,104);
+          d0 = ((7.0/6.0) / (V0*F0))   - ( d0 / (V0*V0*F0_seven_sixths) );
+          V0 = 1. / V0;
 
-      #if DEBUG == 1
-      printf("Intermediate 1: feed values \n");
-      printf("d1 = %.16f\n", d1);
-      printf("d0 = %.16f\n", d0);
-      printf("d4 = %.16f\n", d4);
-      printf("V1 = %.16f\n", V1);
-      printf("V0 = %.16f\n", V0);
-      printf("V2 = %.16f\n", V2);
-      printf("V3 = %.16f\n", V3);
-      printf("V4 = %.16f\n", V4);
-      printf("F1 = %.16f\n", F1);
-      printf("F0 = %.16f\n", F0);
-      printf("F2 = %.16f\n", F2);
-      printf("F3 = %.16f\n", F3);
-      printf("F4 = %.16f\n", F4);
-      #endif
+          #if DEBUG == 1
+          printf("1/V0 = %.16f\n",V0);
+          printf("1/d0 = %.16f\n",d0);
+          #endif
 
-      #if DEBUG == 1
-      printf("\nIntermediate 1: polynomial coeffcients \r\n");
-      printf("alpha0 = %.16f\n", pAmp->alpha0);
-      printf("alpha1 = %.16f\n", pAmp->alpha1);
-      printf("alpha2 = %.16f\n", pAmp->alpha2);
-      printf("alpha3 = %.16f\n", pAmp->alpha3);
-      printf("alpha4 = %.16f\n", pAmp->alpha4);
-      #endif
+          // Get the coefficients of the polynomial for the first intermediate region
+          pAmp->alpha0 = IMRPhenomXHM_Intermediate_Amp_delta0(d1,d0,V1,V2,V3,V0,F1,F2,F3,F0,104); //V3 and F3 will not be used when calling with 104
+          pAmp->alpha1 = IMRPhenomXHM_Intermediate_Amp_delta1(d1,d0,V1,V2,V3,V0,F1,F2,F3,F0,104);
+          pAmp->alpha2 = IMRPhenomXHM_Intermediate_Amp_delta2(d1,d0,V1,V2,V3,V0,F1,F2,F3,F0,104);
+          pAmp->alpha3 = IMRPhenomXHM_Intermediate_Amp_delta3(d1,d0,V1,V2,V3,V0,F1,F2,F3,F0,104);
+          pAmp->alpha4 = IMRPhenomXHM_Intermediate_Amp_delta4(d1,d0,V1,V2,V3,V0,F1,F2,F3,F0,104);
 
-      //Update left collocation point for the 2nd intermediate region
-      F1 = F0;
-      V1 = V0;
-      d1 = d0;
+          #if DEBUG == 1
+          printf("Intermediate 1: feed values \n");
+          printf("d1 = %.16f\n", d1);
+          printf("d0 = %.16f\n", d0);
+          printf("d4 = %.16f\n", d4);
+          printf("V1 = %.16f\n", V1);
+          printf("V0 = %.16f\n", V0);
+          printf("V2 = %.16f\n", V2);
+          printf("V3 = %.16f\n", V3);
+          printf("V4 = %.16f\n", V4);
+          printf("F1 = %.16f\n", F1);
+          printf("F0 = %.16f\n", F0);
+          printf("F2 = %.16f\n", F2);
+          printf("F3 = %.16f\n", F3);
+          printf("F4 = %.16f\n", F4);
+          #endif
 
-      /**** END of first Intermediate region ****/
-    }
-    else{  /** This part is used both when we have a single intermediate region and for the second intermediate region **/
-      pAmp->fAmpMatchInt12 = 0;
-      pAmp->alpha0 = 1;
-      pAmp->alpha1 = 1;
-      pAmp->alpha2 = 1;
-      pAmp->alpha3 = 1;
-      pAmp->alpha4 = 1;
-
-      /** More vetos ***/
-      if(pWFHM->IntermediateAmpVeto == 1 && pWFHM->IMRPhenomXHMIntermediateAmpVersion==105){  // only 21 mode
-        IMRPhenomXHM_Intermediate_Amplitude_Veto(&V2, &V3, pWFHM, pWF22); // this changes the order of the polynomial to 4 or 3
-        #if DEBUG == 1
-        printf("VETO: Intermediate Amp Veto\n");
-        printf("V2 = %.16f\n",V2);
-        printf("V3 = %.16f\n",V3);
-        #endif
-      }
+          #if DEBUG == 1
+          printf("\nIntermediate 1: polynomial coeffcients \r\n");
+          printf("alpha0 = %.16f\n", pAmp->alpha0);
+          printf("alpha1 = %.16f\n", pAmp->alpha1);
+          printf("alpha2 = %.16f\n", pAmp->alpha2);
+          printf("alpha3 = %.16f\n", pAmp->alpha3);
+          printf("alpha4 = %.16f\n", pAmp->alpha4);
+          #endif
 
-      if(pWFHM->RingdownAmpVeto == 1){    // only 21, 32 mode
-        IMRPhenomXHM_Ringdown_Amplitude_Veto(&V2, &V3, V4, pWFHM, pWF22); // If satisfied, remove the 2 inter collocation points
-        #if DEBUG == 1
-        printf("VETO: Ringdown Amp Veto\n");
-        printf("V2 = %.16f\n",V2);
-        printf("V3 = %.16f\n",V3);
-        #endif
-      }
+          //Update left collocation point for the 2nd intermediate region
+          F1 = F0;
+          V1 = V0;
+          d1 = d0;
 
-      if(pWFHM->IMRPhenomXHMIntermediateAmpVersion==105 && pAmp->WavyInt==1){
-        if(WavyPoints(V2,V3,V4)==1){
+          /**** END of first Intermediate region ****/
+        }
+        else{  /** This part is used both when we have a single intermediate region and for the second intermediate region **/
+          pAmp->fAmpMatchInt12 = 0;
+          pAmp->alpha0 = 1;
+          pAmp->alpha1 = 1;
+          pAmp->alpha2 = 1;
+          pAmp->alpha3 = 1;
+          pAmp->alpha4 = 1;
+
+          /** More vetos ***/
+          if(pWFHM->IntermediateAmpVeto == 1 && pWFHM->IMRPhenomXHMIntermediateAmpVersion==105){  // only 21 mode
+            IMRPhenomXHM_Intermediate_Amplitude_Veto(&V2, &V3, pWFHM, pWF22); // this changes the order of the polynomial to 4 or 3
+            #if DEBUG == 1
+            printf("VETO: Intermediate Amp Veto\n");
+            printf("V2 = %.16f\n",V2);
+            printf("V3 = %.16f\n",V3);
+            #endif
+          }
+
+          if(pWFHM->RingdownAmpVeto == 1){    // only 21, 32 mode
+            IMRPhenomXHM_Ringdown_Amplitude_Veto(&V2, &V3, V4, pWFHM, pWF22); // If satisfied, remove the 2 inter collocation points
+            #if DEBUG == 1
+            printf("VETO: Ringdown Amp Veto\n");
+            printf("V2 = %.16f\n",V2);
+            printf("V3 = %.16f\n",V3);
+            #endif
+          }
+
+          if(pWFHM->IMRPhenomXHMIntermediateAmpVersion==105 && pAmp->WavyInt==1){
+            if(WavyPoints(V2,V3,V4)==1){
+              V3 = V2;
+              F3 = F2;
+              V2 = 1.;
+              pWFHM->IMRPhenomXHMIntermediateAmpVersion=1042;
+              #if DEBUG == 1
+              printf("VETO: Wavy Inter colloc points\n");
+              printf("V2 = %.16f\n",V2);
+              printf("V3 = %.16f\n",V3);
+              #endif
+            }
+          }
+
+          if((pWF22->q>40. && pWF22->chi1L>0.9 && V2!=1 && V3!=1) ||
+          (pWFHM->modeTag==32 && (pWFHM->IMRPhenomXHMIntermediateAmpVersion != 101) && ((pWF22->q>2.5 && pWF22->chi1L<-0.6 && pWF22->chi2L>0) || (pWF22->chi1L<-0.9&&pWF22->chi2L<-0.9))) ||
+          (pWFHM->modeTag==21 && pWF22->eta<0.23 && pWF22->chi1L>0.7 && pWF22->chi2L<-0.5)){
+            V2 = 1.;
+            V3 = 1.;
+            pWFHM->IMRPhenomXHMIntermediateAmpVersion = 1032;
+            #if DEBUG == 1
+            printf("VETO: veto regions\n");
+            printf("V2 = %.16f\n",V2);
+            printf("V3 = %.16f\n",V3);
+            #endif
+          }
+          /*** End of vetos **/
+        }
+
+        // The reconstruction function (Update_Intermediate_Amplitude_Coefficients) assumes that F3 is the point with value.
+        // If F3 was removed in the veto the we replace it with F2
+        if(V3 == 1.){
           V3 = V2;
           F3 = F2;
           V2 = 1.;
-          pWFHM->IMRPhenomXHMIntermediateAmpVersion=1042;
-          #if DEBUG == 1
-          printf("VETO: Wavy Inter colloc points\n");
-          printf("V2 = %.16f\n",V2);
-          printf("V3 = %.16f\n",V3);
-          #endif
         }
-      }
 
-      if((pWF22->q>40. && pWF22->chi1L>0.9 && V2!=1 && V3!=1) ||
-      (pWFHM->modeTag==32 && (pWFHM->IMRPhenomXHMIntermediateAmpVersion != 101) && ((pWF22->q>2.5 && pWF22->chi1L<-0.6 && pWF22->chi2L>0) || (pWF22->chi1L<-0.9&&pWF22->chi2L<-0.9))) ||
-      (pWFHM->modeTag==21 && pWF22->eta<0.23 && pWF22->chi1L>0.7 && pWF22->chi2L<-0.5)){
-        V2 = 1.;
-        V3 = 1.;
-        pWFHM->IMRPhenomXHMIntermediateAmpVersion = 1032;
+        /*
+        Reconstruct the phenomenological coefficients for the intermediate ansatz
+        */
+
+        // Store the values for the reconstruction.
+        pAmp->v1 = V1;
+        pAmp->v2 = V2;
+        pAmp->v3 = V3;
+        pAmp->v4 = V4;
+        pAmp->f1 = F1;
+        pAmp->f2 = F2;
+        pAmp->f3 = F3;
+        pAmp->f4 = F4;
+        pAmp->d1 = d1;
+        pAmp->d4 = d4;
+
         #if DEBUG == 1
-        printf("VETO: veto regions\n");
-        printf("V2 = %.16f\n",V2);
-        printf("V3 = %.16f\n",V3);
+        printf("\nIntermediate Amplitude Input \r\n");
+        printf("\nIMRPhenomXHMIntermediateAmpVersion = %i \r\n", pWFHM->IMRPhenomXHMIntermediateAmpVersion);
+        printf("V1 = %.16f\n", V1);
+        printf("V2 = %.16f\n", V2);
+        printf("V3 = %.16f\n", V3);
+        printf("V4 = %.16f\n", V4);
+        printf("F1 = %.16f\n", F1);
+        printf("F2 = %.16f\n", F2);
+        printf("F3 = %.16f\n", F3);
+        printf("F4 = %.16f\n", F4);
+        printf("d1 = %.16f\n", d1);
+        printf("d4 = %.16f\n", d4);
+        printf("fAmpMatchIn = %.16f\n", pAmp->fAmpMatchIN);
         #endif
-      }
-      /*** End of vetos **/
-    }
 
-    // The reconstruction function (Update_Intermediate_Amplitude_Coefficients) assumes that F3 is the point with value.
-    // If F3 was removed in the veto the we replace it with F2
-    if(V3 == 1.){
-      V3 = V2;
-      F3 = F2;
-      V2 = 1.;
-    }
-
-    /*
-    Reconstruct the phenomenological coefficients for the intermediate ansatz
-    */
-
-    // Store the values for the reconstruction.
-    pAmp->v1 = V1;
-    pAmp->v2 = V2;
-    pAmp->v3 = V3;
-    pAmp->v4 = V4;
-    pAmp->f1 = F1;
-    pAmp->f2 = F2;
-    pAmp->f3 = F3;
-    pAmp->f4 = F4;
-    pAmp->d1 = d1;
-    pAmp->d4 = d4;
+        // Compute the coefficients of the polynomial
+        Update_Intermediate_Amplitude_Coefficients(pAmp, pWFHM->IMRPhenomXHMIntermediateAmpVersion);
 
-    #if DEBUG == 1
-    printf("\nIntermediate Amplitude Input \r\n");
-    printf("\nIMRPhenomXHMIntermediateAmpVersion = %i \r\n", pWFHM->IMRPhenomXHMIntermediateAmpVersion);
-    printf("V1 = %.16f\n", V1);
-    printf("V2 = %.16f\n", V2);
-    printf("V3 = %.16f\n", V3);
-    printf("V4 = %.16f\n", V4);
-    printf("F1 = %.16f\n", F1);
-    printf("F2 = %.16f\n", F2);
-    printf("F3 = %.16f\n", F3);
-    printf("F4 = %.16f\n", F4);
-    printf("d1 = %.16f\n", d1);
-    printf("d4 = %.16f\n", d4);
-    printf("fAmpMatchIn = %.16f\n", pAmp->fAmpMatchIN);
-    #endif
 
-    // Compute the coefficients of the polynomial
-    Update_Intermediate_Amplitude_Coefficients(pAmp, pWFHM->IMRPhenomXHMIntermediateAmpVersion);
+        #if DEBUG == 1
+        printf("\nIntermediate polynomial coeffcients Before ChoosePolOrder \r\n");
+        printf("\nIMRPhenomXHMIntermediateAmpVersion = %i \r\n", pWFHM->IMRPhenomXHMIntermediateAmpVersion);
+        printf("delta0 = %.16f\n", pAmp->delta0);
+        printf("delta1 = %.16f\n", pAmp->delta1);
+        printf("delta2 = %.16f\n", pAmp->delta2);
+        printf("delta3 = %.16f\n", pAmp->delta3);
+        printf("delta4 = %.16f\n", pAmp->delta4);
+        printf("delta5 = %.16f\n", pAmp->delta5);
+        printf("fAmpMatchIn = %.16f\n", pAmp->fAmpMatchIN);
+        #endif
 
+        // Check that the polynomial does not cross zero, because the actual reconstructing function is the inverse of this polynomial
+        // If it crosses zero, then remove one collocation and lower the order of the polynomial.
+        ChoosePolOrder(pWFHM, pAmp);
 
-    #if DEBUG == 1
-    printf("\nIntermediate polynomial coeffcients Before ChoosePolOrder \r\n");
-    printf("\nIMRPhenomXHMIntermediateAmpVersion = %i \r\n", pWFHM->IMRPhenomXHMIntermediateAmpVersion);
-    printf("delta0 = %.16f\n", pAmp->delta0);
-    printf("delta1 = %.16f\n", pAmp->delta1);
-    printf("delta2 = %.16f\n", pAmp->delta2);
-    printf("delta3 = %.16f\n", pAmp->delta3);
-    printf("delta4 = %.16f\n", pAmp->delta4);
-    printf("delta5 = %.16f\n", pAmp->delta5);
-    printf("fAmpMatchIn = %.16f\n", pAmp->fAmpMatchIN);
-    #endif
+        #if DEBUG == 1
+        printf("\nIMRPhenomXHMIntermediateAmpVersion = %i \r\n", pWFHM->IMRPhenomXHMIntermediateAmpVersion);
+        printf("\nIntermediate polynomial coeffcients After ChoosePolOrder\r\n");
+        printf("delta0 = %.16f\n", pAmp->delta0);
+        printf("delta1 = %.16f\n", pAmp->delta1);
+        printf("delta2 = %.16f\n", pAmp->delta2);
+        printf("delta3 = %.16f\n", pAmp->delta3);
+        printf("delta4 = %.16f\n", pAmp->delta4);
+        printf("delta5 = %.16f\n", pAmp->delta5);
+        printf("fAmpMatchIn = %.16f\n", pAmp->fAmpMatchIN);
+        #endif
+    }// END of 122018 version
 
-    // Check that the polynomial does not cross zero, because the actual reconstructing function is the inverse of this polynomial
-    // If it crosses zero, then remove one collocation and lower the order of the polynomial.
-    ChoosePolOrder(pWFHM, pAmp);
+  }
 
-    #if DEBUG == 1
-    printf("\nIMRPhenomXHMIntermediateAmpVersion = %i \r\n", pWFHM->IMRPhenomXHMIntermediateAmpVersion);
-    printf("\nIntermediate polynomial coeffcients After ChoosePolOrder\r\n");
-    printf("delta0 = %.16f\n", pAmp->delta0);
-    printf("delta1 = %.16f\n", pAmp->delta1);
-    printf("delta2 = %.16f\n", pAmp->delta2);
-    printf("delta3 = %.16f\n", pAmp->delta3);
-    printf("delta4 = %.16f\n", pAmp->delta4);
-    printf("delta5 = %.16f\n", pAmp->delta5);
-    printf("fAmpMatchIn = %.16f\n", pAmp->fAmpMatchIN);
-    #endif
+double RescaleFactor(IMRPhenomX_UsefulPowers *powers_of_Mf, IMRPhenomXHMAmpCoefficients *pAmp, UINT2 rescalefactor){
+  double factor = 0.;
+  switch(rescalefactor){
+      case 0:{ // Strain
+         factor = 1.;
+         break;
+      }          
+      case 1:{ // 22factor
+          factor = pAmp->ampNorm * powers_of_Mf->m_seven_sixths;
+          break;
+      }
+      case 2:{ // lmfactor
+          if (pAmp->PNdominantlmpower == 1) factor = pAmp->PNdominant * powers_of_Mf->m_seven_sixths * pAmp->PNdominantlm * powers_of_Mf->one_third;
+          if (pAmp->PNdominantlmpower == 2) factor = pAmp->PNdominant * powers_of_Mf->m_seven_sixths * pAmp->PNdominantlm * powers_of_Mf->two_thirds;
+          if (pAmp->PNdominantlmpower == 3) factor = pAmp->PNdominant * powers_of_Mf->m_seven_sixths * pAmp->PNdominantlm * powers_of_Mf->itself;
+          if (pAmp->PNdominantlmpower == 4) factor = pAmp->PNdominant * powers_of_Mf->m_seven_sixths * pAmp->PNdominantlm * powers_of_Mf->four_thirds;
+          break;
+      }
+      default:{XLAL_ERROR_REAL8(XLAL_EINVAL,"Error in RescaleFactor: version %i is not valid. Recommended version is 1.", rescalefactor);}
   }
+  return factor;
+}
 
 
 /*******************************************/
@@ -1404,7 +1767,8 @@ void IMRPhenomXHM_GetPhaseCoefficients(IMRPhenomXHMAmpCoefficients *pAmp, IMRPhe
     pPhase->alpha2 = 0.0;
     pPhase->alphaL = 0.0;
 
-
+  
+    
     // set number of collocation points used (depends on the mode)
     int nCollocationPts_inter=pWFHM->nCollocPtsInterPhase;
     // define mass-ratio that discriminates between EMR and rest of cases
@@ -1421,7 +1785,7 @@ void IMRPhenomXHM_GetPhaseCoefficients(IMRPhenomXHMAmpCoefficients *pAmp, IMRPhe
     //for each collocation point, call fit giving the value of the phase derivative at that point
     for(int i = 0; i<N_MAX_COEFFICIENTS_PHASE_INTER; i++)
     {
-        pPhase->CollocationPointsValuesPhaseInter[i] = pPhase->IntermediatePhaseFits[modeint*N_MAX_COEFFICIENTS_PHASE_INTER+i](pWF22->eta,pWF22->STotR,pWF22->chi1L,pWF22->chi2L,pWFHM->IMRPhenomXHMIntermediatePhaseVersion);
+        pPhase->CollocationPointsValuesPhaseInter[i] = pPhase->IntermediatePhaseFits[modeint*N_MAX_COEFFICIENTS_PHASE_INTER+i](pWF22,pWFHM->IMRPhenomXHMIntermediatePhaseFitsVersion);
         // time-shift wf so that modes peak around t=0
         // our hybrids are built so that their inverse FT peaks ~500 M before the end of the time-interval. Our reconstructed WFs will have the same normalization, so we shift the phase here so that the modes peak around t=0
         pPhase->CollocationPointsValuesPhaseInter[i]=pPhase->CollocationPointsValuesPhaseInter[i]+pWFHM->DeltaT;
@@ -1434,13 +1798,13 @@ void IMRPhenomXHM_GetPhaseCoefficients(IMRPhenomXHMAmpCoefficients *pAmp, IMRPhe
 
     /************** Inspiral: rescale PhenX and apply PN corrections *********/
 
-
     //collect all the phenX inspiral coefficients
-    double phenXnonLog[]={pPhase22->phi0,pPhase22->phi1,pPhase22->phi2,pPhase22->phi3,pPhase22->phi4,pPhase22->phi5,pPhase22->phi6,pPhase22->phi7,pPhase22->phi8,pPhase22->phi9,0.,0,0};
-    double phenXLog[]={0.,0.,0.,0.,0.,pPhase22->phi5L,pPhase22->phi6L,0.,pPhase22->phi8L,pPhase22->phi9L,0,0,0};
+    double phenXnonLog[]={pPhase22->phi0,pPhase22->phi1,pPhase22->phi2,pPhase22->phi3,pPhase22->phi4,pPhase22->phi5,pPhase22->phi6,pPhase22->phi7,pPhase22->phi8,pPhase22->phi9,0.,0,0,0};
+    double phenXLog[]={0.,0.,0.,0.,0.,pPhase22->phi5L,pPhase22->phi6L,0.,pPhase22->phi8L,pPhase22->phi9L,0,0,0,0};
     double pseudoPN[]={0.,0.,0.,0.,0.,0.,0.,0.,pPhase22->sigma1,pPhase22->sigma2,pPhase22->sigma3,pPhase22->sigma4,pPhase22->sigma5};
-
-
+    
+  
+    
     //rescale the coefficients of phenX by applying phi_lm(f)~m/2 *phi_22(2/m f)
     // for more details, see Appendix D of the paper
     double m_over_2=emm*0.5, two_over_m=1./m_over_2;
@@ -1471,7 +1835,7 @@ void IMRPhenomXHM_GetPhaseCoefficients(IMRPhenomXHMAmpCoefficients *pAmp, IMRPhe
     // else use some phenomenological fits: the fits give the coefficient of a linear-in-f term to be added to the orbital phase
     else{
 
-      pPhase->LambdaPN= pPhase->InspiralPhaseFits[pWFHM->modeInt](pWF22->eta,pWF22->STotR,pWF22->chi1L,pWF22->chi2L,pWFHM->IMRPhenomXHMInspiralPhaseVersion);
+      pPhase->LambdaPN= pPhase->InspiralPhaseFits[pWFHM->modeInt](pWF22,pWFHM->IMRPhenomXHMInspiralPhaseVersion);
       #if DEBUG == 1
       printf("\nLambdaPN = %.16f\n", pPhase->LambdaPN);
       #endif
@@ -1565,15 +1929,15 @@ void IMRPhenomXHM_GetPhaseCoefficients(IMRPhenomXHMAmpCoefficients *pAmp, IMRPhe
         if(pWFHM->ell==pWFHM->emm) wlm=2;
         else wlm=pWFHM->emm/3.;
 
-        pPhase->alpha2=1./pow(pWFHM->fRING,2)*wlm*IMRPhenomXHM_RD_Phase_22_alpha2(pWF22->eta,pWF22->STotR,pWF22->chi1L,pWF22->chi2L,pWFHM->IMRPhenomXHMRingdownPhaseVersion);
+        pPhase->alpha2=1./pow(pWFHM->fRING,2)*wlm*IMRPhenomXHM_RD_Phase_22_alpha2(pWF22,pWFHM->IMRPhenomXHMRingdownPhaseVersion);
 
 
         // compute alphaL
-        pPhase->alphaL=eta_m1*IMRPhenomXHM_RD_Phase_22_alphaL(pWF22->eta,pWF22->STotR,pWF22->chi1L,pWF22->chi2L,pWFHM->IMRPhenomXHMRingdownPhaseVersion);
+        pPhase->alphaL=eta_m1*IMRPhenomXHM_RD_Phase_22_alphaL(pWF22,pWFHM->IMRPhenomXHMRingdownPhaseVersion);
 
         #if DEBUG == 1
-        printf("alpha2_fit=%f\n",IMRPhenomXHM_RD_Phase_22_alpha2(pWF22->eta,pWF22->STotR,pWF22->chi1L,pWF22->chi2L,pWFHM->IMRPhenomXHMRingdownPhaseVersion));
-        printf("Ringdown parameters: \n alpha2=%f \n alphaL=%f\n",pPhase->alpha2,pPhase->alphaL);
+        printf("alpha2_fit=%.16e\n",IMRPhenomXHM_RD_Phase_22_alpha2(pWF22,pWFHM->IMRPhenomXHMRingdownPhaseVersion));
+        printf("Ringdown parameters: \n alpha2=%.16e \n alphaL=%.16e\n",pPhase->alpha2,pPhase->alphaL);
         # endif
 
         // compute spherical-harmonic phase and its first derivative at matching frequency --used to glue RD and intermediate regions--
@@ -1611,17 +1975,15 @@ void IMRPhenomXHM_GetPhaseCoefficients(IMRPhenomXHMAmpCoefficients *pAmp, IMRPhe
         // we first compute the full spherical-harmonic-basis waveforms at three points
         double complex SphericalWF[3];
         double fstep=0.0000001;
-
+        
         for(int i=0; i<3; i++){
 
           double FF=fcutRD+(i-1)*fstep;
           IMRPhenomX_UsefulPowers powers_of_FF;
           IMRPhenomX_Initialize_Powers(&powers_of_FF,FF);
-          SphericalWF[i]=SpheroidalToSpherical(FF, &powers_of_FF, pAmp22, pPhase22, pAmp, pPhase, pWFHM, pWF22);
-
+          SphericalWF[i]=SpheroidalToSpherical(&powers_of_FF, pAmp22, pPhase22, pAmp, pPhase, pWFHM, pWF22);
         }
 
-
         long double phase_args[]={fmodl(carg(SphericalWF[0]),2.*LAL_PI),fmodl(carg(SphericalWF[1]),2.*LAL_PI),fmodl(carg(SphericalWF[2]),2.*LAL_PI)};
 
         // make sure that all the three points belong to the same branch of mod
@@ -1640,7 +2002,7 @@ void IMRPhenomXHM_GetPhaseCoefficients(IMRPhenomXHMAmpCoefficients *pAmp, IMRPhe
         double d2phi0RD=fstep_m1*fstep_m1*(phase_args[2]-2.*phase_args[1]+phase_args[0]);
 
         #if DEBUG == 1
-        printf("dphi0ref=%f\t d2phi0ref=%f\n",pPhase->dphi0RD,d2phi0RD);
+        printf("dphi0ref=%.16e\t d2phi0ref=%.16e\n",pPhase->dphi0RD,d2phi0RD);
         # endif
 
           // To achieve a smoother transition with the intermediate region (IR), we feed into the intermediate-region reconstruction the first and second derivative of the reconstructed ringdown phase, see Eq. (5.6)
@@ -1728,7 +2090,7 @@ void IMRPhenomXHM_GetPhaseCoefficients(IMRPhenomXHMAmpCoefficients *pAmp, IMRPhe
 
     #if DEBUG == 1
     printf("Intermediate region coefficients:\n");
-    printf("c0=%f\n c1=%f\n c2=%f\n c3=%f\n c4=%f\n cL=%f\n", pPhase->c0,pPhase->c1,pPhase->c2,pPhase->c3,pPhase->c4,pPhase->cL);
+    printf("c0=%.16e\n c1=%.16e\n c2=%.16e\n c3=%.16e\n c4=%.16e\n cL=%.16e\n", pPhase->c0,pPhase->c1,pPhase->c2,pPhase->c3,pPhase->c4,pPhase->cL);
     #endif
 
     gsl_vector_free(b);
@@ -1741,16 +2103,15 @@ void IMRPhenomXHM_GetPhaseCoefficients(IMRPhenomXHMAmpCoefficients *pAmp, IMRPhe
 
     //glue inspiral and intermediate
     IMRPhenomX_Initialize_Powers(&powers_of_f,fcutInsp);
-
     pPhase->C1INSP=IMRPhenomXHM_Inter_Phase_Ansatz(fcutInsp, &powers_of_f,pWFHM, pPhase)-IMRPhenomXHM_Inspiral_Phase_Ansatz(fcutInsp, &powers_of_f, pPhase);
     pPhase->CINSP=-(pPhase->C1INSP*fcutInsp)+IMRPhenomXHM_Inter_Phase_AnsatzInt(fcutInsp, &powers_of_f,pWFHM, pPhase)-IMRPhenomXHM_Inspiral_Phase_AnsatzInt(fcutInsp, &powers_of_f, pPhase);
-
     //glue ringdown and intermediate regions
     IMRPhenomX_Initialize_Powers(&powers_of_f,fcutRD);
 
     pPhase->C1RD=IMRPhenomXHM_Inter_Phase_Ansatz(fcutRD, &powers_of_f,pWFHM, pPhase)-pPhase->dphi0RD;
     pPhase->CRD=-pPhase->C1RD*fcutRD+IMRPhenomXHM_Inter_Phase_AnsatzInt(fcutRD, &powers_of_f,pWFHM, pPhase)-pPhase->phi0RD;
-
+    
+    
     // we now have a C1 reconstruction of the phase
     // below we align each mode so that at low-f its relative phase wrt the 22 agrees with PN
     double falign;
@@ -1774,7 +2135,7 @@ void IMRPhenomXHM_GetPhaseCoefficients(IMRPhenomXHMAmpCoefficients *pAmp, IMRPhe
     }
 
     // we determine the phase normalization of each mode by imposing Eq. (4.13), i.e. phi_lm(fref)-m/2 phi_22(2/m fref)~3.*LAL_PI_4*(1-m_over_2)
-    double deltaphiLM=m_over_2*(1./pWF22->eta*IMRPhenomX_Phase_22(two_over_m*falign, &powers_of_f,pPhase22,pWF22)+pWFHM->phaseshift + pWFHM->phiref22)+pWFHM->timeshift*falign-3.*LAL_PI_4*(1-m_over_2)-(IMRPhenomXHM_Inspiral_Phase_AnsatzInt(falign, &powers_of_falign,pPhase)+pPhase->C1INSP*falign+pPhase->CINSP);
+    double deltaphiLM = m_over_2*(1./pWF22->eta*IMRPhenomX_Phase_22(two_over_m*falign, &powers_of_f,pPhase22,pWF22)+pWFHM->phaseshift + pWFHM->phiref22)+pWFHM->timeshift*falign-3.*LAL_PI_4*(1-m_over_2)-(IMRPhenomXHM_Inspiral_Phase_AnsatzInt(falign, &powers_of_falign,pPhase)+pPhase->C1INSP*falign+pPhase->CINSP);
     pPhase->deltaphiLM=fmod(deltaphiLM,2.*LAL_PI);
 
     #if DEBUG == 1
@@ -1819,7 +2180,7 @@ void IMRPhenomXHM_GetPhaseCoefficients(IMRPhenomXHMAmpCoefficients *pAmp, IMRPhe
   fprintf(file,"\n*** Phase Intermediate ***\n f_i\t dphi(f_i)\n");
 
   for(int i = 0; i<N_MAX_COEFFICIENTS_PHASE_INTER; i++)
-      fprintf(file, "%.16f \t %.16f \n", pPhase->CollocationPointsFreqsPhaseInter[i], pPhase->IntermediatePhaseFits[pWFHM->modeInt*N_MAX_COEFFICIENTS_PHASE_INTER+i](pWF22->eta,pWF22->STotR,pWF22->chi1L,pWF22->chi2L,pWFHM->IMRPhenomXHMIntermediatePhaseVersion));
+      fprintf(file, "%.16f \t %.16f \n", pPhase->CollocationPointsFreqsPhaseInter[i], pPhase->IntermediatePhaseFits[pWFHM->modeInt*N_MAX_COEFFICIENTS_PHASE_INTER+i](pWF22,pWFHM->IMRPhenomXHMIntermediatePhaseFitsVersion));
 
 
   if(pWFHM->modeTag==32){
@@ -1831,8 +2192,8 @@ void IMRPhenomXHM_GetPhaseCoefficients(IMRPhenomXHMAmpCoefficients *pAmp, IMRPhe
 
       fprintf(file, "\n*** Ringdown Phase Spheroidal ***\n f_i \t dphi(f_i)\n");
       for(int i=0; i<pWFHM->nCollocPtsRDPhase; i++)
-          fprintf(file, "%.16f \t %.16f \n", pPhase->CollocationPointsFreqsPhaseRD[i],pPhase->RingdownPhaseFits[i](pWF22->eta,pWF22->STotR,pWF22->chi1L,pWF22->chi2L,pWFHM->IMRPhenomXHMRingdownPhaseVersion));
-      fprintf(file,"Deltadphi=%.16f\n Deltaphi=%.16f \n", IMRPhenomXHM_RD_Phase_32_SpheroidalTimeShift(pWF22->eta,pWF22->STotR,pWF22->chi1L,pWF22->chi2L,pWFHM->IMRPhenomXHMRingdownPhaseVersion),IMRPhenomXHM_RD_Phase_32_SpheroidalPhaseShift(pWF22->eta,pWF22->STotR,pWF22->chi1L,pWF22->chi2L,pWFHM->IMRPhenomXHMRingdownPhaseVersion));
+          fprintf(file, "%.16f \t %.16f \n", pPhase->CollocationPointsFreqsPhaseRD[i],pPhase->RingdownPhaseFits[i](pWF22,pWFHM->IMRPhenomXHMRingdownPhaseVersion));
+      fprintf(file,"Deltadphi=%.16f\n Deltaphi=%.16f \n", IMRPhenomXHM_RD_Phase_32_SpheroidalTimeShift(pWF22,pWFHM->IMRPhenomXHMRingdownPhaseVersion),IMRPhenomXHM_RD_Phase_32_SpheroidalPhaseShift(pWF22,pWFHM->IMRPhenomXHMRingdownPhaseVersion));
 
   }
 
@@ -1876,40 +2237,62 @@ void  GetSpheroidalCoefficients(IMRPhenomXHMPhaseCoefficients *pPhase, IMRPhenom
     printf("Initialize RD CollocPtsFreqs:\n");
     #endif
 
-    // first fill-in the collocation points for the phase
-    for(int i=0; i<nCollocationPts_RD_Phase; i++)
-    {
+    if(pWFHM->IMRPhenomXHMRingdownPhaseVersion == 122019){
+        // first fill-in the collocation points for the phase
+        for(int i=0; i<nCollocationPts_RD_Phase; i++)
+        {
 
-      CollocValuesPhaseRingdown[i] =pPhase->RingdownPhaseFits[i](pWF22->eta,pWF22->STotR,pWF22->chi1L,pWF22->chi2L,pWFHM->IMRPhenomXHMRingdownPhaseVersion);
-      CollocFreqsPhaseRingdown[i] =pPhase->CollocationPointsFreqsPhaseRD[i];
-      gsl_vector_set(b,i,CollocValuesPhaseRingdown[i]);
-      REAL8 ff=CollocFreqsPhaseRingdown[i], ffm1=1./ff, ffm2=ffm1*ffm1;
-      REAL8 fpowers[]={1., (pWFHM->fDAMP)/(pow(pWFHM->fDAMP,2)+pow(ff-(pWFHM->fRING),2)),ffm2,ffm2*ffm2};
-      for(int j=0; j<nCollocationPts_RD_Phase; j++)
-      gsl_matrix_set(A,i,j,fpowers[j]);
+          CollocValuesPhaseRingdown[i] =pPhase->RingdownPhaseFits[i](pWF22,pWFHM->IMRPhenomXHMRingdownPhaseFitsVersion);
+          CollocFreqsPhaseRingdown[i] =pPhase->CollocationPointsFreqsPhaseRD[i];
+          gsl_vector_set(b,i,CollocValuesPhaseRingdown[i]);
+          REAL8 ff=CollocFreqsPhaseRingdown[i], ffm1=1./ff, ffm2=ffm1*ffm1;
+          REAL8 fpowers[]={1., (pWFHM->fDAMP)/(pow(pWFHM->fDAMP,2)+pow(ff-(pWFHM->fRING),2)),ffm2,ffm2*ffm2};
+          for(int j=0; j<nCollocationPts_RD_Phase; j++)
+          gsl_matrix_set(A,i,j,fpowers[j]);
 
+        }
+    }
+    else{
+        for(int i = 0; i < nCollocationPts_RD_Phase; i++){
+            CollocValuesPhaseRingdown[i] = pPhase->RingdownPhaseFits[i](pWF22,pWFHM->IMRPhenomXHMRingdownPhaseFitsVersion);
+            CollocFreqsPhaseRingdown[i]  = pPhase->CollocationPointsFreqsPhaseRD[i];
+            gsl_vector_set(b,i,CollocValuesPhaseRingdown[i]);
+            REAL8 ff = CollocFreqsPhaseRingdown[i], ffm1 = 1./ff, ffm2 = ffm1 * ffm1;
+            REAL8 lorentzian = pWFHM->fDAMP / (pWFHM->fDAMP * pWFHM->fDAMP + (ff - pWFHM->fRING) * (ff - pWFHM->fRING));
+            REAL8 fpowers[] = {1., ffm1, ffm2, ffm2 * ffm2, lorentzian};
+            for(int j = 0; j < nCollocationPts_RD_Phase; j++){
+                gsl_matrix_set(A, i, j, fpowers[j]); // Ansatz spheroidal
+            }
+        }
     }
 
     #if DEBUG == 1
     printf("Collocation points in ringdown region:\n");
     for(int i=0; i<nCollocationPts_RD_Phase; i++){
-      printf("p%d=(%f,%f)\n",i+1,CollocFreqsPhaseRingdown[i],CollocValuesPhaseRingdown[i]);
+      printf("p%d=(%.16e,%.16e)\n",i+1,CollocFreqsPhaseRingdown[i],CollocValuesPhaseRingdown[i]);
     }
-
     #endif
+
     // solve the linear system of Eq. (6.8)
     gsl_linalg_LU_decomp(A,p,&s);
     gsl_linalg_LU_solve(A,p,b,x);
 
-    /* ansatz: alpha0 + (alpha2)/(f^2)+ (alpha4)/(f^4)  + alphaL*(fdamplm)/((fdamplm)^2 + (f - fRDlm)^2)*/
-
-    pPhase->alpha0_S = gsl_vector_get(x,0);
-    pPhase->alphaL_S = gsl_vector_get(x,1);
-    pPhase->alpha2_S = gsl_vector_get(x,2);
-    pPhase->alpha4_S = gsl_vector_get(x,3);
+    if(pWFHM->IMRPhenomXHMRingdownPhaseVersion == 122019){
+        /* ansatz: alpha0 + (alpha2)/(f^2)+ (alpha4)/(f^4)  + alphaL*(fdamplm)/((fdamplm)^2 + (f - fRDlm)^2)*/
+        pPhase->alpha0_S = gsl_vector_get(x,0);
+        pPhase->alphaL_S = gsl_vector_get(x,1);
+        pPhase->alpha2_S = gsl_vector_get(x,2);
+        pPhase->alpha4_S = gsl_vector_get(x,3);
+    }
+    else{
+        //printf("New Spheroidal Version. Getting coefficients\n");
+        for(int i=0; i<nCollocationPts_RD_Phase; i++){
+            pPhase->RDCoefficient[i] = gsl_vector_get(x, i);
+        }
+    }
 
     #if DEBUG == 1
-    printf("**********\n alpha0_S=%f \n alphaL_S=%f \n alpha2_S=%f \n alpha4_S=%f \n \n ", pPhase->alpha0_S, pPhase->alphaL_S, pPhase->alpha2_S, pPhase->alpha4_S);
+    printf("**********\n alpha0_S=%.16e \n alphaL_S=%.16e \n alpha2_S=%.16e \n alpha4_S=%.16e \n \n ", pPhase->alpha0_S, pPhase->alphaL_S, pPhase->alpha2_S, pPhase->alpha4_S);
     #endif
 
     gsl_vector_free(b);
@@ -1924,18 +2307,50 @@ void  GetSpheroidalCoefficients(IMRPhenomXHMPhaseCoefficients *pPhase, IMRPhenom
     double frefRD=pWF22->fRING+pWF22->fDAMP;
     IMRPhenomX_Initialize_Powers(&powers_of_FREF,frefRD);
     // here we call a fit for dphiS(fref)-dphi22(fref)
-    double tshift=IMRPhenomXHM_RD_Phase_32_SpheroidalTimeShift(pWF22->eta,pWF22->STotR,pWF22->chi1L,pWF22->chi2L,pWFHM->IMRPhenomXHMRingdownPhaseVersion);
+    double tshift=IMRPhenomXHM_RD_Phase_32_SpheroidalTimeShift(pWF22,pWFHM->IMRPhenomXHMRingdownPhaseFitsVersion);
 
     // we compute dphi22(fref)
     IMRPhenomX_Phase_22_ConnectionCoefficients(pWF22,pPhase22);
     pWFHM->timeshift=IMRPhenomX_TimeShift_22(pPhase22, pWF22);
-    double dphi22ref=1./pWF22->eta*IMRPhenomX_dPhase_22(frefRD, &powers_of_FREF,pPhase22,pWF22)+pWFHM->timeshift;
+    
+    pPhase->phi0_S = 0;
 
     // we impose that dphiS(fref)-dphi22(fref) has the value given by our fit
-    pPhase->alpha0_S = pPhase->alpha0_S +dphi22ref+tshift-IMRPhenomXHM_RD_Phase_Ansatz(frefRD,&powers_of_FREF,pWFHM,pPhase);
+    if(pWFHM->IMRPhenomXHMRingdownPhaseVersion == 122019){
+        double dphi22ref = 1./pWF22->eta*IMRPhenomX_dPhase_22(frefRD, &powers_of_FREF,pPhase22,pWF22)+pWFHM->timeshift;
+        pPhase->alpha0_S = pPhase->alpha0_S +dphi22ref+tshift-IMRPhenomXHM_RD_Phase_Ansatz(frefRD,&powers_of_FREF,pWFHM,pPhase);
+    }
+    else{
+        // REAL8 psi4tostrain=XLALSimIMRPhenomXPsi4ToStrain(pWF22->eta, pWF22->STotR, pWF22->dchi);
+        // pPhase->RDCoefficient[0] -= 2.*LAL_PI*(500+psi4tostrain);
+        double dphi22ref = 1./pWF22->eta*IMRPhenomX_dPhase_22(frefRD, &powers_of_FREF,pPhase22,pWF22)+pWFHM->timeshift;
+        double dphi32ref = IMRPhenomXHM_RD_Phase_Ansatz(frefRD,&powers_of_FREF,pWFHM,pPhase);
+        pPhase->RDCoefficient[0] += dphi22ref+tshift-dphi32ref;
+        //printf("dphi32ref before time shift = %.16e\n", dphi32ref);
+        // printf("fittimeshift = %.16e\n", tshift);
+        // printf("Time shift = %.16e\n", dphi22ref+tshift-dphi32ref);
+        // printf("dphi22ref = %.16e\n", dphi22ref);
+        // printf("dphi32ref = %.16e\n", IMRPhenomXHM_RD_Phase_Ansatz(frefRD,&powers_of_FREF,pWFHM,pPhase));
+        //pPhase->RDCoefficient[0] += (dphi22ref + tshift - IMRPhenomXHM_RD_Phase_Ansatz(frefRD, &powers_of_FREF, pWFHM, pPhase));
+        //pPhase->RDCoefficient[5] -= 2.*LAL_PI*(500+psi4tostrain);
+        INT4 exponent = 5; // a + b / f^5
+        REAL8 ff = pWFHM->fRING + 2 * pWFHM->fDAMP;
+        IMRPhenomX_UsefulPowers powers_of_ff;
+        IMRPhenomX_Initialize_Powers(&powers_of_ff, ff);
+        pPhase->RDCoefficient[nCollocationPts_RD_Phase + 1] = -IMRPhenomXHM_RD_Phase_DerAnsatz(ff, &powers_of_ff, pWFHM, pPhase) * pow(ff, exponent + 1) / exponent;
+        pPhase->RDCoefficient[nCollocationPts_RD_Phase] = IMRPhenomXHM_RD_Phase_Ansatz(ff, &powers_of_ff, pWFHM, pPhase) - pPhase->RDCoefficient[nCollocationPts_RD_Phase + 1] / pow(ff, exponent);
+        pPhase->RDCoefficient[nCollocationPts_RD_Phase + 2] = IMRPhenomXHM_RD_Phase_AnsatzInt(ff, &powers_of_ff, pWFHM, pPhase) - (pPhase->RDCoefficient[5]*ff - 0.25 * pPhase->RDCoefficient[6] * powers_of_ff.m_four);
+        pWFHM->fPhaseRDflat = ff;   
+    }
 
     /*************** phase-shift of spheroidal ansatz *******************/
-    frefRD=pWF22->fRING;
+    //if(pWFHM->IMRPhenomXHMRingdownPhaseVersion == 122019 || pWFHM->IMRPhenomXHMRingdownPhaseVersion == 20221114){
+        frefRD = pWF22->fRING;
+    // }
+    // else{
+    //     frefRD = pWF22->fRING - pWF22->fDAMP;
+    //     //pWFHM->phaseshift += LAL_PI;
+    // }
     IMRPhenomX_Initialize_Powers(&powers_of_FREF,frefRD);
 
     /* we compute phi22(fref) */
@@ -1943,17 +2358,25 @@ void  GetSpheroidalCoefficients(IMRPhenomXHMPhaseCoefficients *pPhase, IMRPhenom
     IMRPhenomX_Initialize_Powers(&powers_of_MfRef,pWF22->MfRef);
     pWFHM->phiref22 = -1./pWF22->eta*IMRPhenomX_Phase_22(pWF22->MfRef, &powers_of_MfRef, pPhase22, pWF22) - pWFHM->timeshift*pWF22->MfRef - pWFHM->phaseshift + 2.0*pWF22->phi0 + LAL_PI_4;
     double phi22ref=1./pWF22->eta*IMRPhenomX_Phase_22(frefRD, &powers_of_FREF,pPhase22,pWF22) + pWFHM->timeshift*frefRD + pWFHM->phaseshift + pWFHM->phiref22;
+    // printf("phi22ref = %.16e\n", phi22ref);
+    // printf("phi32ref = %.16e\n", IMRPhenomXHM_RD_Phase_AnsatzInt(frefRD,&powers_of_FREF,pWFHM,pPhase));
+    // printf("frefRD = %.16e\n", frefRD);
+    
     // we call a fit for Mod[phiS(fref)-phi22(fref),2*Pi]
-    double phishift=IMRPhenomXHM_RD_Phase_32_SpheroidalPhaseShift(pWF22->eta,pWF22->STotR,pWF22->chi1L,pWF22->chi2L,pWFHM->IMRPhenomXHMRingdownPhaseVersion);
+    double phishift=IMRPhenomXHM_RD_Phase_32_SpheroidalPhaseShift(pWF22,pWFHM->IMRPhenomXHMRingdownPhaseFitsVersion);
+    //if (pWFHM->IMRPhenomXHMRingdownPhaseVersion == 20221114) phishift += LAL_PI;
+    //printf("fitphaseshift = %.6f\n", phishift);
 
-    pPhase->phi0_S = 0;
     //we adjust the relative phase of our reconstruction
-    pPhase->phi0_S= phi22ref-IMRPhenomXHM_RD_Phase_AnsatzInt(frefRD,&powers_of_FREF,pWFHM,pPhase)+phishift;
-
-
+    pPhase->phi0_S= phi22ref - IMRPhenomXHM_RD_Phase_AnsatzInt(frefRD,&powers_of_FREF,pWFHM,pPhase) + phishift;
+    // printf("phaseshift = %.16e\n", pPhase->phi0_S);
+    // 
+    // printf("phi32ref = %.16e\n", IMRPhenomXHM_RD_Phase_AnsatzInt(frefRD,&powers_of_FREF,pWFHM,pPhase));
+    
+        
     #if DEBUG == 1
-    printf("**********\n alpha0_S=%f \n alphaL_S=%f \n alpha2_S=%f \n alpha4_S=%f \n \n ", pPhase->alpha0_S, pPhase->alphaL_S, pPhase->alpha2_S, pPhase->alpha4_S);
-    printf("**********\n **Spheroidal reconstruction parameters:**\n \n phi0_S=%f \n alpha0_S=%f \n alphaL_S=%f \n alpha2_S=%f \n alpha4_S=%f \n \n ",pPhase->phi0_S, pPhase->alpha0_S, pPhase->alphaL_S, pPhase->alpha2_S, pPhase->alpha4_S);
+    printf("**********\n alpha0_S=%.16e \n alphaL_S=%.16e \n alpha2_S=%.16e \n alpha4_S=%.16e \n \n ", pPhase->alpha0_S, pPhase->alphaL_S, pPhase->alpha2_S, pPhase->alpha4_S);
+    printf("**********\n **Spheroidal reconstruction parameters:**\n \n phi0_S=%.16e \n alpha0_S=%.16e \n alphaL_S=%.16e \n alpha2_S=%.16e \n alpha4_S=%.16e \n \n ",pPhase->phi0_S, pPhase->alpha0_S, pPhase->alphaL_S, pPhase->alpha2_S, pPhase->alpha4_S);
     #endif
 
 
@@ -1974,31 +2397,39 @@ void  GetSpheroidalCoefficients(IMRPhenomXHMPhaseCoefficients *pPhase, IMRPhenom
 */
 
   // In principle this could be generalized to the 43 mode: for the time being, assume the mode solved for is only the 32.
-  double complex SpheroidalToSpherical(double ff, IMRPhenomX_UsefulPowers *powers_of_f, IMRPhenomXAmpCoefficients *pAmp22, IMRPhenomXPhaseCoefficients *pPhase22, IMRPhenomXHMAmpCoefficients *pAmplm, IMRPhenomXHMPhaseCoefficients *pPhaselm, IMRPhenomXHMWaveformStruct *pWFlm, IMRPhenomXWaveformStruct *pWF22)
+  COMPLEX16 SpheroidalToSpherical(IMRPhenomX_UsefulPowers *powers_of_Mf, IMRPhenomXAmpCoefficients *pAmp22, IMRPhenomXPhaseCoefficients *pPhase22, IMRPhenomXHMAmpCoefficients *pAmplm, IMRPhenomXHMPhaseCoefficients *pPhaselm, IMRPhenomXHMWaveformStruct *pWFlm, IMRPhenomXWaveformStruct *pWF22)
   {
+    REAL8 Mf = powers_of_Mf->itself;
     // Compute the 22 mode using PhenomX functions. This gives the 22 mode rescaled with the leading order.  This is because the 32 is also rescaled.
-    double amp22=XLALSimIMRPhenomXRingdownAmplitude22AnsatzAnalytical(ff, pWF22->fRING, pWF22->fDAMP, pAmp22->gamma1, pAmp22->gamma2, pAmp22->gamma3);
-    double phi22=1./pWF22->eta*IMRPhenomX_Phase_22(ff, powers_of_f, pPhase22,pWF22) + pWFlm->timeshift*ff + pWFlm->phaseshift + pWFlm->phiref22;
-    complex double wf22R = amp22*cexp(I * phi22);
+    REAL8 amp22=XLALSimIMRPhenomXRingdownAmplitude22AnsatzAnalytical(Mf, pWF22->fRING, pWF22->fDAMP, pAmp22->gamma1, pAmp22->gamma2, pAmp22->gamma3);
+    REAL8 phi22=1./pWF22->eta*IMRPhenomX_Phase_22(Mf, powers_of_Mf, pPhase22,pWF22) + pWFlm->timeshift*Mf + pWFlm->phaseshift + pWFlm->phiref22;
+    COMPLEX16 wf22R = amp22 * cexp(I * phi22);
+    if (pWFlm->IMRPhenomXHMRingdownAmpVersion != 0){
+        wf22R *= pWFlm->ampNorm * powers_of_Mf->m_seven_sixths;
+    }
     // Compute 32 mode in spheroidal.
-    double amplm=IMRPhenomXHM_RD_Amp_Ansatz(ff, pWFlm, pAmplm);
-    double philm=IMRPhenomXHM_RD_Phase_AnsatzInt(ff, powers_of_f,pWFlm, pPhaselm);
+    REAL8 amplm=IMRPhenomXHM_RD_Amp_Ansatz(powers_of_Mf, pWFlm, pAmplm);
+    REAL8 philm=IMRPhenomXHM_RD_Phase_AnsatzInt(Mf, powers_of_Mf,pWFlm, pPhaselm);
     // Do the rotation.
-    double complex sphericalWF_32=conj(pWFlm->mixingCoeffs[2]) * wf22R + conj(pWFlm->mixingCoeffs[3])*amplm*cexp(I*philm);
+    COMPLEX16 sphericalWF_32=conj(pWFlm->mixingCoeffs[2]) * wf22R + conj(pWFlm->mixingCoeffs[3])*amplm*cexp(I*philm);
     return sphericalWF_32;
 
   }
 
   // If the 22 mode has been previously computed, we use it here for the rotation.
-  double complex SpheroidalToSphericalRecycle(double ff, IMRPhenomX_UsefulPowers *powers_of_f, COMPLEX16 wf22, IMRPhenomXHMAmpCoefficients *pAmplm, IMRPhenomXHMPhaseCoefficients *pPhaselm, IMRPhenomXHMWaveformStruct *pWFlm)
+  COMPLEX16 SpheroidalToSphericalRecycle(IMRPhenomX_UsefulPowers *powers_of_Mf, COMPLEX16 wf22, IMRPhenomXHMAmpCoefficients *pAmplm, IMRPhenomXHMPhaseCoefficients *pPhaselm, IMRPhenomXHMWaveformStruct *pWFlm)
   {
     // The input 22 in the whole 22, and for the rotation we have to rescaled with the leading order. This is because the 32 is also rescaled.
-    complex double wf22R = wf22/(powers_of_f->m_seven_sixths * pWFlm->Amp0);
+    //complex double wf22R = wf22/(powers_of_f->m_seven_sixths * pWF22->amp0);
+    COMPLEX16 wf22R = wf22 / pWFlm->Amp0;
+    if (pWFlm->IMRPhenomXHMRingdownAmpVersion == 0){
+        wf22R /= (pWFlm->ampNorm * powers_of_Mf->m_seven_sixths);
+    }
     // Compute 32 mode in spheroidal.
-    double amplm=IMRPhenomXHM_RD_Amp_Ansatz(ff, pWFlm, pAmplm);
-    double philm=IMRPhenomXHM_RD_Phase_AnsatzInt(ff, powers_of_f,pWFlm, pPhaselm);
+    REAL8 amplm=IMRPhenomXHM_RD_Amp_Ansatz(powers_of_Mf, pWFlm, pAmplm);
+    REAL8 philm=IMRPhenomXHM_RD_Phase_AnsatzInt(powers_of_Mf->itself, powers_of_Mf, pWFlm, pPhaselm);
     // Do the rotation
-    double complex sphericalWF_32 = conj(pWFlm->mixingCoeffs[2])*wf22R  +  conj(pWFlm->mixingCoeffs[3])*amplm*cexp(I*philm);
+    COMPLEX16 sphericalWF_32 = conj(pWFlm->mixingCoeffs[2])*wf22R  +  conj(pWFlm->mixingCoeffs[3])*amplm*cexp(I*philm);
     return sphericalWF_32;
 
   }
@@ -2021,104 +2452,99 @@ void  GetSpheroidalCoefficients(IMRPhenomXHMPhaseCoefficients *pPhase, IMRPhenom
   /*******************************************************************************/
 
   // WITHOUT mode mixing. It returns the whole amplitude (in NR units) without the normalization factor of the 22: sqrt[2 * eta / (3 * pi^(1/3))]
-  double IMRPhenomXHM_Amplitude_noModeMixing(double f, IMRPhenomX_UsefulPowers *powers_of_f, IMRPhenomXHMAmpCoefficients *pAmp, IMRPhenomXHMWaveformStruct *pWF) {
-
+  REAL8 IMRPhenomXHM_Amplitude_noModeMixing(IMRPhenomX_UsefulPowers *powers_of_Mf, IMRPhenomXHMAmpCoefficients *pAmp, IMRPhenomXHMWaveformStruct *pWF) {
     // If it is an odd mode and equal black holes case this mode is zero.
     if(pWF->Ampzero==1){
       return 0.;
     }
-
-    double factor = powers_of_f->m_seven_sixths;
-
+    
     // Use step function to only calculate IMR regions in approrpiate frequency regime
+    REAL8 Amp, Mf = powers_of_Mf->itself;
     // Inspiral range
-    if (!IMRPhenomX_StepFuncBool(f, pAmp->fAmpMatchIN))
-    {
-      double AmpIns =  IMRPhenomXHM_Inspiral_Amp_Ansatz(powers_of_f, pWF, pAmp);
-      return AmpIns*factor;
+    if (!IMRPhenomX_StepFuncBool(Mf, pAmp->fAmpMatchIN)){
+      Amp = IMRPhenomXHM_Inspiral_Amp_Ansatz(powers_of_Mf, pWF, pAmp);
     }
     // MRD range
-    if (IMRPhenomX_StepFuncBool(f, pAmp->fAmpMatchIM))
-    {
-      double AmpMRD = IMRPhenomXHM_RD_Amp_Ansatz(powers_of_f->itself, pWF, pAmp);
-      return AmpMRD*factor;
+    else if (IMRPhenomX_StepFuncBool(Mf, pAmp->fAmpMatchIM)){
+      // if (pWFHM->fAmpRDfalloff > 0 && IMRPhenomX_StepFuncBool(Mf, pWFHM->fAmpRDfalloff)){
+      //     Amp = pAmp->RDCoefficient[3] * exp(- pAmp->RDCoefficient[4] * (Mf - pWFHM->fAmpRDfalloff));
+      // }
+      //else{
+          Amp = IMRPhenomXHM_RD_Amp_Ansatz(powers_of_Mf, pWF, pAmp);
+          if (pWF->IMRPhenomXHMRingdownAmpVersion == 0) Amp *= powers_of_Mf->m_seven_sixths * pWF->ampNorm;
+     //}
     }
     /* Intermediate range */
     // First intermediate region.
-    if ((pWF->AmpEMR==1) && !IMRPhenomX_StepFuncBool(f, pAmp->fAmpMatchInt12))
-    {
+    else if ((pWF->AmpEMR==1) && !IMRPhenomX_StepFuncBool(Mf, pAmp->fAmpMatchInt12)){
       INT4 tmp = pAmp->InterAmpPolOrder;
       pAmp->InterAmpPolOrder = 1042;
-      double AmpInt1 = IMRPhenomXHM_Intermediate_Amp_Ansatz(powers_of_f, pAmp);
+      Amp = IMRPhenomXHM_Intermediate_Amp_Ansatz(powers_of_Mf, pWF, pAmp);
       pAmp->InterAmpPolOrder = tmp;
-      return AmpInt1;
     }
-    //Second intermediate region
-    double AmpInt = IMRPhenomXHM_Intermediate_Amp_Ansatz(powers_of_f, pAmp);
-    return AmpInt;
+    else{  //Second intermediate region
+        Amp = IMRPhenomXHM_Intermediate_Amp_Ansatz(powers_of_Mf, pWF, pAmp);
+    }
+    if (Amp < 0 && pWF->IMRPhenomXHMReleaseVersion != 122019) Amp = FALSE_ZERO;
+    return Amp;
   }
 
   // WITH mode mixing. It returns the whole amplitude (in NR units) without the normalization factor of the 22: sqrt[2 * eta / (3 * pi^(1/3))].
-  double IMRPhenomXHM_Amplitude_ModeMixing(double f, IMRPhenomX_UsefulPowers *powers_of_f, IMRPhenomXHMAmpCoefficients *pAmp, IMRPhenomXHMPhaseCoefficients *pPhase, IMRPhenomXHMWaveformStruct *pWF, IMRPhenomXAmpCoefficients *pAmp22, IMRPhenomXPhaseCoefficients *pPhase22, IMRPhenomXWaveformStruct *pWF22) {
-    double factor = powers_of_f->m_seven_sixths;
+  REAL8 IMRPhenomXHM_Amplitude_ModeMixing(IMRPhenomX_UsefulPowers *powers_of_Mf, IMRPhenomXHMAmpCoefficients *pAmp, IMRPhenomXHMPhaseCoefficients *pPhase, IMRPhenomXHMWaveformStruct *pWF, IMRPhenomXAmpCoefficients *pAmp22, IMRPhenomXPhaseCoefficients *pPhase22, IMRPhenomXWaveformStruct *pWF22) {
     // Use step function to only calculate IMR regions in approrpiate frequency regime
+    REAL8 Amp, Mf = powers_of_Mf->itself;
     // Inspiral range
-    if (!IMRPhenomX_StepFuncBool(f, pAmp->fAmpMatchIN))
-    {
-      double AmpIns =  IMRPhenomXHM_Inspiral_Amp_Ansatz(powers_of_f, pWF, pAmp);
-      return AmpIns*factor;
+    if (!IMRPhenomX_StepFuncBool(Mf, pAmp->fAmpMatchIN)){
+      Amp =  IMRPhenomXHM_Inspiral_Amp_Ansatz(powers_of_Mf, pWF, pAmp);
     }
     // MRD range
-    if (IMRPhenomX_StepFuncBool(f, pAmp->fAmpMatchIM))
-    {
-      double AmpMRD = cabs(SpheroidalToSpherical(f, powers_of_f, pAmp22, pPhase22, pAmp, pPhase, pWF, pWF22));
-      return AmpMRD*factor;
+    else if (IMRPhenomX_StepFuncBool(Mf, pAmp->fAmpMatchIM)){
+      Amp = cabs(SpheroidalToSpherical(powers_of_Mf, pAmp22, pPhase22, pAmp, pPhase, pWF, pWF22));
+      if (pWF->IMRPhenomXHMRingdownAmpVersion == 0) Amp *= powers_of_Mf->m_seven_sixths * pWF->ampNorm;
     }
     /* Intermediate range */
     // First intermediate region
-    if ((pWF->AmpEMR==1) && !IMRPhenomX_StepFuncBool(f, pAmp->fAmpMatchInt12))
-    {
+    else if ((pWF->AmpEMR==1) && !IMRPhenomX_StepFuncBool(Mf, pAmp->fAmpMatchInt12)){
       INT4 tmp = pAmp->InterAmpPolOrder;
       pAmp->InterAmpPolOrder = 1042;
-      double AmpInt1 = IMRPhenomXHM_Intermediate_Amp_Ansatz(powers_of_f, pAmp);
+      Amp = IMRPhenomXHM_Intermediate_Amp_Ansatz(powers_of_Mf, pWF, pAmp);
       pAmp->InterAmpPolOrder = tmp;
-      return AmpInt1;
     }
     //Second intermediate region
-    double AmpInt = IMRPhenomXHM_Intermediate_Amp_Ansatz(powers_of_f, pAmp);
-    return AmpInt;
+    else{
+        Amp = IMRPhenomXHM_Intermediate_Amp_Ansatz(powers_of_Mf, pWF, pAmp);
+    }
+    if (Amp < 0 && pWF->IMRPhenomXHMReleaseVersion != 122019) Amp = FALSE_ZERO;
+    return Amp;
   }
 
   // WITH mode mixing and recycling the previously computed 22 mode. It returns the whole amplitude (in NR units) without the normalization factor of the 22: sqrt[2 * eta / (3 * pi^(1/3))].
-  double IMRPhenomXHM_Amplitude_ModeMixingRecycle(double f, IMRPhenomX_UsefulPowers *powers_of_f, COMPLEX16 wf22, IMRPhenomXHMAmpCoefficients *pAmp, IMRPhenomXHMPhaseCoefficients *pPhase, IMRPhenomXHMWaveformStruct *pWF) {
-    //  double f_seven_sixths = powers_of_f->seven_sixths;
-    double factor = powers_of_f->m_seven_sixths;
+  REAL8 IMRPhenomXHM_Amplitude_ModeMixingRecycle(IMRPhenomX_UsefulPowers *powers_of_Mf, COMPLEX16 wf22, IMRPhenomXHMAmpCoefficients *pAmp, IMRPhenomXHMPhaseCoefficients *pPhase, IMRPhenomXHMWaveformStruct *pWF) {
     // Use step function to only calculate IMR regions in approrpiate frequency regime
+    REAL8 Amp, Mf = powers_of_Mf->itself;
     // Inspiral range
-    if (!IMRPhenomX_StepFuncBool(f, pAmp->fAmpMatchIN))
-    {
-      double AmpIns =  IMRPhenomXHM_Inspiral_Amp_Ansatz(powers_of_f, pWF, pAmp);
-      return AmpIns*factor;
+    if (!IMRPhenomX_StepFuncBool(Mf, pAmp->fAmpMatchIN)){
+      Amp =  IMRPhenomXHM_Inspiral_Amp_Ansatz(powers_of_Mf, pWF, pAmp);
     }
     // MRD range
-    if (IMRPhenomX_StepFuncBool(f, pAmp->fAmpMatchIM))
-    {
-      double AmpMRD = cabs(SpheroidalToSphericalRecycle(f, powers_of_f, wf22, pAmp, pPhase, pWF));
-      return AmpMRD*factor;
+    else if (IMRPhenomX_StepFuncBool(Mf, pAmp->fAmpMatchIM)){
+      Amp = cabs(SpheroidalToSphericalRecycle(powers_of_Mf, wf22, pAmp, pPhase, pWF));
+      if (pWF->IMRPhenomXHMRingdownAmpVersion == 0) Amp *= powers_of_Mf->m_seven_sixths * pWF->ampNorm;
     }
     /* Intermediate range */
     // First intermediate region
-    if ((pWF->AmpEMR==1) && !IMRPhenomX_StepFuncBool(f, pAmp->fAmpMatchInt12))
-    {
+    else if ((pWF->AmpEMR==1) && !IMRPhenomX_StepFuncBool(Mf, pAmp->fAmpMatchInt12)){ // FIXME: why was the second condition commented?
       INT4 tmp = pAmp->InterAmpPolOrder;
       pAmp->InterAmpPolOrder = 1042;
-      double AmpInt1 = IMRPhenomXHM_Intermediate_Amp_Ansatz(powers_of_f, pAmp);
+      Amp = IMRPhenomXHM_Intermediate_Amp_Ansatz(powers_of_Mf, pWF, pAmp);
       pAmp->InterAmpPolOrder = tmp;
-      return AmpInt1;
     }
     //Second intermediate region
-    double AmpInt = IMRPhenomXHM_Intermediate_Amp_Ansatz(powers_of_f, pAmp);
-    return AmpInt;
+    else{
+        Amp = IMRPhenomXHM_Intermediate_Amp_Ansatz(powers_of_Mf, pWF, pAmp);
+    }
+    if (Amp < 0 && pWF->IMRPhenomXHMReleaseVersion != 122019) Amp = FALSE_ZERO;
+    return Amp;
   }
 
 
@@ -2126,65 +2552,68 @@ void  GetSpheroidalCoefficients(IMRPhenomXHMPhaseCoefficients *pPhase, IMRPhenom
   /*  Compute IMRPhenomXHM PHASE given a phase coefficients struct pPhase        */
   /*******************************************************************************/
 
-  // WITHOUT mode mixing.
-  double IMRPhenomXHM_Phase_noModeMixing(double f, IMRPhenomX_UsefulPowers *powers_of_f, IMRPhenomXHMPhaseCoefficients *pPhase, IMRPhenomXHMWaveformStruct *pWF, UNUSED IMRPhenomXWaveformStruct *pWF22)
+// WITHOUT mode mixing.
+REAL8 IMRPhenomXHM_Phase_noModeMixing(IMRPhenomX_UsefulPowers *powers_of_Mf, IMRPhenomXHMPhaseCoefficients *pPhase, IMRPhenomXHMWaveformStruct *pWF, UNUSED IMRPhenomXWaveformStruct *pWF22)
+{
+  REAL8 Mf = powers_of_Mf->itself;
+  // Inspiral range, f < fPhaseInsMax
+  if (!IMRPhenomX_StepFuncBool(Mf, pPhase->fPhaseMatchIN))
   {
-    // Inspiral range, f < fPhaseInsMax
-    if (!IMRPhenomX_StepFuncBool(f, pPhase->fPhaseMatchIN))
-    {
-      double PhiIns = IMRPhenomXHM_Inspiral_Phase_AnsatzInt(f, powers_of_f, pPhase);
-      return PhiIns + pPhase->C1INSP*f + pPhase->CINSP + pPhase->deltaphiLM;
-    }
-    // MRD range, f > fPhaseIntMax
-    if (IMRPhenomX_StepFuncBool(f, pPhase->fPhaseMatchIM))
-    {
-      double PhiMRD = IMRPhenomXHM_RD_Phase_AnsatzInt(f, powers_of_f, pWF, pPhase);
-      return PhiMRD + pPhase->C1RD*f + pPhase->CRD + pPhase->deltaphiLM;
-    }
-    //Intermediate range, fPhaseInsMax < f < fPhaseIntMax
-    double PhiInt = IMRPhenomXHM_Inter_Phase_AnsatzInt(f, powers_of_f, pWF, pPhase);
-    return PhiInt + pPhase->deltaphiLM;
+      REAL8 PhiIns = IMRPhenomXHM_Inspiral_Phase_AnsatzInt(Mf, powers_of_Mf, pPhase);
+      return PhiIns + pPhase->C1INSP*Mf + pPhase->CINSP + pPhase->deltaphiLM;
   }
+  // MRD range, f > fPhaseIntMax
+  if (IMRPhenomX_StepFuncBool(Mf, pPhase->fPhaseMatchIM))
+  {
+      REAL8 PhiMRD = IMRPhenomXHM_RD_Phase_AnsatzInt(Mf, powers_of_Mf, pWF, pPhase);
+      return PhiMRD + pPhase->C1RD*Mf + pPhase->CRD + pPhase->deltaphiLM;
+  }
+  //Intermediate range, fPhaseInsMax < f < fPhaseIntMax
+  REAL8 PhiInt = IMRPhenomXHM_Inter_Phase_AnsatzInt(Mf, powers_of_Mf, pWF, pPhase);
+  return PhiInt + pPhase->deltaphiLM;
+}
 
-  // WITH mode mixing.
-  double IMRPhenomXHM_Phase_ModeMixing(double f, IMRPhenomX_UsefulPowers *powers_of_f,IMRPhenomXHMAmpCoefficients *pAmp, IMRPhenomXHMPhaseCoefficients *pPhase, IMRPhenomXHMWaveformStruct *pWF,  IMRPhenomXAmpCoefficients *pAmp22, IMRPhenomXPhaseCoefficients *pPhase22, IMRPhenomXWaveformStruct *pWF22)
+// WITH mode mixing.
+REAL8 IMRPhenomXHM_Phase_ModeMixing(IMRPhenomX_UsefulPowers *powers_of_Mf, IMRPhenomXHMAmpCoefficients *pAmp, IMRPhenomXHMPhaseCoefficients *pPhase, IMRPhenomXHMWaveformStruct *pWF,  IMRPhenomXAmpCoefficients *pAmp22, IMRPhenomXPhaseCoefficients *pPhase22, IMRPhenomXWaveformStruct *pWF22)
+{
+  REAL8 Mf = powers_of_Mf->itself;
+  // Inspiral range, f < fPhaseInsMax
+  if (!IMRPhenomX_StepFuncBool(Mf, pPhase->fPhaseMatchIN))
   {
-    // Inspiral range, f < fPhaseInsMax
-    if (!IMRPhenomX_StepFuncBool(f, pPhase->fPhaseMatchIN))
-    {
-      double PhiIns = IMRPhenomXHM_Inspiral_Phase_AnsatzInt(f, powers_of_f, pPhase);
-      return PhiIns + pPhase->C1INSP*f + pPhase->CINSP + pPhase->deltaphiLM;
-    }
-    // MRD range, f > fPhaseIntMax
-    if (IMRPhenomX_StepFuncBool(f, pPhase->fPhaseMatchIM))
-    {
-      double PhiMRD = carg(SpheroidalToSpherical(f, powers_of_f, pAmp22, pPhase22, pAmp, pPhase, pWF, pWF22));
-      return PhiMRD + pPhase->C1RD*f + pPhase->CRD + pPhase->deltaphiLM;
-    }
-    //Intermediate range, fPhaseInsMax < f < fPhaseIntMax
-    double PhiInt = IMRPhenomXHM_Inter_Phase_AnsatzInt(f, powers_of_f, pWF, pPhase);
-    return PhiInt + pPhase->deltaphiLM;
+      REAL8 PhiIns = IMRPhenomXHM_Inspiral_Phase_AnsatzInt(Mf, powers_of_Mf, pPhase);
+      return PhiIns + pPhase->C1INSP*Mf + pPhase->CINSP + pPhase->deltaphiLM;
+  }
+  // MRD range, f > fPhaseIntMax
+  if (IMRPhenomX_StepFuncBool(Mf, pPhase->fPhaseMatchIM))
+  {
+      REAL8 PhiMRD = carg(SpheroidalToSpherical(powers_of_Mf, pAmp22, pPhase22, pAmp, pPhase, pWF, pWF22));
+      return PhiMRD + pPhase->C1RD*Mf + pPhase->CRD + pPhase->deltaphiLM;
   }
+  //Intermediate range, fPhaseInsMax < f < fPhaseIntMax
+  REAL8 PhiInt = IMRPhenomXHM_Inter_Phase_AnsatzInt(Mf, powers_of_Mf, pWF, pPhase);
+  return PhiInt + pPhase->deltaphiLM;
+}
 
-  // WITH mode mixing and recycling the previously computed 22 mode.
-  double IMRPhenomXHM_Phase_ModeMixingRecycle(double f, IMRPhenomX_UsefulPowers *powers_of_f, COMPLEX16 wf22, IMRPhenomXHMAmpCoefficients *pAmp, IMRPhenomXHMPhaseCoefficients *pPhase, IMRPhenomXHMWaveformStruct *pWF)
+// WITH mode mixing and recycling the previously computed 22 mode.
+REAL8 IMRPhenomXHM_Phase_ModeMixingRecycle(IMRPhenomX_UsefulPowers *powers_of_Mf, COMPLEX16 wf22, IMRPhenomXHMAmpCoefficients *pAmp, IMRPhenomXHMPhaseCoefficients *pPhase, IMRPhenomXHMWaveformStruct *pWF)
+{
+  REAL8 Mf = powers_of_Mf->itself;
+  // Inspiral range, f < fPhaseInsMax
+  if (!IMRPhenomX_StepFuncBool(Mf, pPhase->fPhaseMatchIN))
   {
-    // Inspiral range, f < fPhaseInsMax
-    if (!IMRPhenomX_StepFuncBool(f, pPhase->fPhaseMatchIN))
-    {
-      double PhiIns = IMRPhenomXHM_Inspiral_Phase_AnsatzInt(f, powers_of_f, pPhase);
-      return PhiIns + pPhase->C1INSP*f + pPhase->CINSP + pPhase->deltaphiLM;
-    }
-    // MRD range, f > fPhaseIntMax
-    if (IMRPhenomX_StepFuncBool(f, pPhase->fPhaseMatchIM))
-    {
-      double PhiMRD = carg(SpheroidalToSphericalRecycle(f, powers_of_f, wf22, pAmp, pPhase, pWF));
-      return PhiMRD + pPhase->C1RD*f + pPhase->CRD + pPhase->deltaphiLM;
-    }
-    //Intermediate range, fPhaseInsMax < f < fPhaseIntMax
-    double PhiInt = IMRPhenomXHM_Inter_Phase_AnsatzInt(f, powers_of_f, pWF, pPhase);
-    return PhiInt + pPhase->deltaphiLM;
+      REAL8 PhiIns = IMRPhenomXHM_Inspiral_Phase_AnsatzInt(Mf, powers_of_Mf, pPhase);
+      return PhiIns + pPhase->C1INSP*Mf + pPhase->CINSP + pPhase->deltaphiLM;
   }
+  // MRD range, f > fPhaseIntMax
+  if (IMRPhenomX_StepFuncBool(Mf, pPhase->fPhaseMatchIM))
+  {
+      REAL8 PhiMRD = carg(SpheroidalToSphericalRecycle(powers_of_Mf, wf22, pAmp, pPhase, pWF));
+      return PhiMRD + pPhase->C1RD*Mf + pPhase->CRD + pPhase->deltaphiLM;
+  }
+  //Intermediate range, fPhaseInsMax < f < fPhaseIntMax
+  REAL8 PhiInt = IMRPhenomXHM_Inter_Phase_AnsatzInt(Mf, powers_of_Mf, pWF, pPhase);
+  return PhiInt + pPhase->deltaphiLM;
+}
 
 
   /*****************/
@@ -2259,10 +2688,10 @@ void  GetSpheroidalCoefficients(IMRPhenomXHMPhaseCoefficients *pPhase, IMRPhenom
     fprintf(file,"delta3  = %.16f\n", pAmp->delta3);
     fprintf(file,"delta4  = %.16f\n", pAmp->delta4);
     fprintf(file,"delta5  = %.16f\n", pAmp->delta5);
-    fprintf(file,"alambda = %.20f\n", pAmp->alambda); //Ringdown region
-    fprintf(file,"lambda  = %.16f\n", pAmp->lambda);
-    fprintf(file,"sigma   = %.16f\n", pAmp->sigma);
-    fprintf(file,"lc      = %.16f\n", pAmp->lc);
+    fprintf(file,"alambda = %.20f\n", pAmp->RDCoefficient[0]); //Ringdown region
+    fprintf(file,"lambda  = %.16f\n", pAmp->RDCoefficient[1]);
+    fprintf(file,"sigma   = %.16f\n", pAmp->RDCoefficient[2]);
+    fprintf(file,"lc      = %.16f\n", pAmp->RDCoefficient[3]);
     fprintf(file,"alpha0  = %.16f\n", pAmp->alpha0); //First Intermediate region (only for EMR)
     fprintf(file,"alpha1  = %.16f\n", pAmp->alpha1);
     fprintf(file,"alpha2  = %.16f\n", pAmp->alpha2);
diff --git a/lalsimulation/lib/LALSimIMRPhenomXHM_internals.h b/lalsimulation/lib/LALSimIMRPhenomXHM_internals.h
index eb63fe891b644d3b981bd8b4ede786fdae77a093..56ad34dc2d6460f6de95b7f2ad4275f3a42c88f9 100644
--- a/lalsimulation/lib/LALSimIMRPhenomXHM_internals.h
+++ b/lalsimulation/lib/LALSimIMRPhenomXHM_internals.h
@@ -56,6 +56,8 @@ extern "C" {
 
   #define NMAX_INSPIRAL_COEFFICIENTS 13
 
+  #define FALSE_ZERO 1.0e-15
+
   //  You should not declare static functions here, since this file is included in other files apart form the source one.
 
   /*********** Useful Powers of pi **************/
@@ -78,6 +80,8 @@ extern "C" {
   double IMRPhenomXHM_Amplitude_fcutInsp(IMRPhenomXHMWaveformStruct *pWFHM, IMRPhenomXWaveformStruct *pWF22);
   double IMRPhenomXHM_Amplitude_fcutRD(IMRPhenomXHMWaveformStruct *pWFHM, IMRPhenomXWaveformStruct *pWF22);
 
+  double RescaleFactor(IMRPhenomX_UsefulPowers *powers_of_Mf, IMRPhenomXHMAmpCoefficients *pAmp, UINT2 rescalefactor);
+
   /***************** Amplitude coefficients ****************/
   void IMRPhenomXHM_GetAmplitudeCoefficients(IMRPhenomXHMAmpCoefficients *pAmp, IMRPhenomXHMPhaseCoefficients *pPhase, IMRPhenomXAmpCoefficients *pAmp22, IMRPhenomXPhaseCoefficients *pPhase22, IMRPhenomXHMWaveformStruct *pWFHM, IMRPhenomXWaveformStruct *pWF22);
   void IMRPhenomXHM_GetPNAmplitudeCoefficients(IMRPhenomXHMAmpCoefficients *pAmp, IMRPhenomXHMWaveformStruct *pWFHM,  IMRPhenomXWaveformStruct *pWF22);
@@ -85,9 +89,9 @@ extern "C" {
 
   /**************** Amplitude reconstruction ******************/
   // Functions that return suitable ansatz at a given frequency
-  double IMRPhenomXHM_Amplitude_noModeMixing(double f, IMRPhenomX_UsefulPowers *powers_of_f, IMRPhenomXHMAmpCoefficients *pAmp, IMRPhenomXHMWaveformStruct *pWF);
-  double IMRPhenomXHM_Amplitude_ModeMixing(double f, IMRPhenomX_UsefulPowers *powers_of_f, IMRPhenomXHMAmpCoefficients *pAmp, IMRPhenomXHMPhaseCoefficients *pPhase, IMRPhenomXHMWaveformStruct *pWF,  IMRPhenomXAmpCoefficients *pAmp22, IMRPhenomXPhaseCoefficients *pPhase22, IMRPhenomXWaveformStruct *pWF22);
-  double IMRPhenomXHM_Amplitude_ModeMixingRecycle(double f, IMRPhenomX_UsefulPowers *powers_of_f, COMPLEX16 wf22, IMRPhenomXHMAmpCoefficients *pAmp, IMRPhenomXHMPhaseCoefficients *pPhase, IMRPhenomXHMWaveformStruct *pWF);
+  REAL8 IMRPhenomXHM_Amplitude_noModeMixing(IMRPhenomX_UsefulPowers *powers_of_Mf, IMRPhenomXHMAmpCoefficients *pAmp, IMRPhenomXHMWaveformStruct *pWF);
+  REAL8 IMRPhenomXHM_Amplitude_ModeMixing(IMRPhenomX_UsefulPowers *powers_of_Mf, IMRPhenomXHMAmpCoefficients *pAmp, IMRPhenomXHMPhaseCoefficients *pPhase, IMRPhenomXHMWaveformStruct *pWF,  IMRPhenomXAmpCoefficients *pAmp22, IMRPhenomXPhaseCoefficients *pPhase22, IMRPhenomXWaveformStruct *pWF22);
+  REAL8 IMRPhenomXHM_Amplitude_ModeMixingRecycle(IMRPhenomX_UsefulPowers *powers_of_Mf, COMPLEX16 wf22, IMRPhenomXHMAmpCoefficients *pAmp, IMRPhenomXHMPhaseCoefficients *pPhase, IMRPhenomXHMWaveformStruct *pWF);
 
 
 
@@ -102,8 +106,8 @@ extern "C" {
   double GetfcutInsp(IMRPhenomXWaveformStruct *pWF22, IMRPhenomXHMWaveformStruct *pWFHM);
 
   /***************** spheroidal->spherical harmonic conversion  *******************/
-  double complex SpheroidalToSpherical(double ff, IMRPhenomX_UsefulPowers *powers_of_f, IMRPhenomXAmpCoefficients *pAmp22, IMRPhenomXPhaseCoefficients *pPhase22, IMRPhenomXHMAmpCoefficients *pAmplm, IMRPhenomXHMPhaseCoefficients *pPhaselm, IMRPhenomXHMWaveformStruct *pWFlm, IMRPhenomXWaveformStruct *pWF22);
-  double complex SpheroidalToSphericalRecycle(double ff, IMRPhenomX_UsefulPowers *powers_of_f, COMPLEX16 wf22, IMRPhenomXHMAmpCoefficients *pAmplm, IMRPhenomXHMPhaseCoefficients *pPhaselm, IMRPhenomXHMWaveformStruct *pWFlm);
+  COMPLEX16 SpheroidalToSpherical(IMRPhenomX_UsefulPowers *powers_of_Mf, IMRPhenomXAmpCoefficients *pAmp22, IMRPhenomXPhaseCoefficients *pPhase22, IMRPhenomXHMAmpCoefficients *pAmplm, IMRPhenomXHMPhaseCoefficients *pPhaselm, IMRPhenomXHMWaveformStruct *pWFlm, IMRPhenomXWaveformStruct *pWF22);
+  COMPLEX16 SpheroidalToSphericalRecycle(IMRPhenomX_UsefulPowers *powers_of_Mf, COMPLEX16 wf22, IMRPhenomXHMAmpCoefficients *pAmplm, IMRPhenomXHMPhaseCoefficients *pPhaselm, IMRPhenomXHMWaveformStruct *pWFlm);
 
   /***************** spheroidal-harmonic ringdown reconstruction ********************/
   void IMRPhenomXHM_Ringdown_CollocPtsFreqs(IMRPhenomXHMPhaseCoefficients *pPhase,IMRPhenomXHMWaveformStruct *pWFHM, IMRPhenomXWaveformStruct *pWF22);
@@ -115,9 +119,9 @@ extern "C" {
 
   /**************** Phase reconstruction ******************/
   // functions that return suitable ansatz at a given frequency
-  double IMRPhenomXHM_Phase_noModeMixing(double f, IMRPhenomX_UsefulPowers *powers_of_f, IMRPhenomXHMPhaseCoefficients *pPhase, IMRPhenomXHMWaveformStruct *pWF,IMRPhenomXWaveformStruct *pWF22);
-  double IMRPhenomXHM_Phase_ModeMixing(double f, IMRPhenomX_UsefulPowers *powers_of_f, IMRPhenomXHMAmpCoefficients *pAmp, IMRPhenomXHMPhaseCoefficients *pPhase, IMRPhenomXHMWaveformStruct *pWF,IMRPhenomXAmpCoefficients *pAmp22, IMRPhenomXPhaseCoefficients *pPhase22, IMRPhenomXWaveformStruct *pWF22);
-  double IMRPhenomXHM_Phase_ModeMixingRecycle(double f, IMRPhenomX_UsefulPowers *powers_of_f, COMPLEX16 wf22, IMRPhenomXHMAmpCoefficients *pAmp, IMRPhenomXHMPhaseCoefficients *pPhase, IMRPhenomXHMWaveformStruct *pWF);
+  REAL8 IMRPhenomXHM_Phase_noModeMixing(IMRPhenomX_UsefulPowers *powers_of_Mf, IMRPhenomXHMPhaseCoefficients *pPhase, IMRPhenomXHMWaveformStruct *pWF,IMRPhenomXWaveformStruct *pWF22);
+  REAL8 IMRPhenomXHM_Phase_ModeMixing(IMRPhenomX_UsefulPowers *powers_of_Mf, IMRPhenomXHMAmpCoefficients *pAmp, IMRPhenomXHMPhaseCoefficients *pPhase, IMRPhenomXHMWaveformStruct *pWF,IMRPhenomXAmpCoefficients *pAmp22, IMRPhenomXPhaseCoefficients *pPhase22, IMRPhenomXWaveformStruct *pWF22);
+  REAL8 IMRPhenomXHM_Phase_ModeMixingRecycle(IMRPhenomX_UsefulPowers *powers_of_Mf, COMPLEX16 wf22, IMRPhenomXHMAmpCoefficients *pAmp, IMRPhenomXHMPhaseCoefficients *pPhase, IMRPhenomXHMWaveformStruct *pWF);
 
 
   // Debugging function
diff --git a/lalsimulation/lib/LALSimIMRPhenomXHM_multiband.c b/lalsimulation/lib/LALSimIMRPhenomXHM_multiband.c
index a188ce7080b196fcc681fb265b75ff1974af791c..4ca64c29aa782c82dfb31e47d8b889a89acc7d4f 100644
--- a/lalsimulation/lib/LALSimIMRPhenomXHM_multiband.c
+++ b/lalsimulation/lib/LALSimIMRPhenomXHM_multiband.c
@@ -403,6 +403,31 @@ INT4 XLALSimIMRPhenomXMultibandingGrid(
   return nGridsUsed;
 }
 
+
+INT4 deltaF_MergerRingdown(REAL8 *dfmerger, REAL8 *dfringdown, REAL8 resTest, IMRPhenomXHMWaveformStruct *pWFHM, IMRPhenomXHMAmpCoefficients *pAmp, IMRPhenomXHMPhaseCoefficients *pPhase)
+{
+    REAL8 phase_coeff = 0, amp_coeff = 0;
+    if (pWFHM->MixingOn == 0){
+        phase_coeff = pPhase->alphaL;
+    }
+    else{
+        if (pWFHM->IMRPhenomXHMRingdownPhaseVersion == 122019){
+            phase_coeff = pPhase->alphaL_S;
+        }
+        else if(pWFHM->IMRPhenomXHMRingdownPhaseVersion == 122022) {
+            phase_coeff = pPhase->RDCoefficient[4];
+        }
+    }
+    amp_coeff = pAmp->RDCoefficient[1]/(pAmp->RDCoefficient[2]*pWFHM->fDAMP);
+    *dfmerger = deltaF_mergerBin(pWFHM->fDAMP, phase_coeff, resTest);
+    *dfringdown = deltaF_ringdownBin(pWFHM->fDAMP, phase_coeff, amp_coeff, resTest);
+
+    XLAL_CHECK(*dfmerger > 0, XLAL_EFAULT, "dfmerger = %.6e. It must be > 0", *dfmerger);
+    XLAL_CHECK(*dfringdown > 0, XLAL_EFAULT, "dfringdown = %.6e. It must be > 0", *dfringdown);
+
+    return XLAL_SUCCESS;
+}
+
 /**
  * @addtogroup LALSimIMRPhenomX_c
  * @{
@@ -601,6 +626,7 @@ int IMRPhenomXHMMultiBandOneMode(
 
   /* Threshold for the Multibanding. It is a measure of how restrictive it is. Smaller value implies stronger restriction, more points where evaluate the model. */
   REAL8 resTest  = XLALSimInspiralWaveformParamsLookupPhenomXHMThresholdMband(lalParams);
+  XLAL_CHECK(resTest > 0, XLAL_EDOM, "Multibanding threshold must be > 0.");
   UINT4 ampinterpolorder = XLALSimInspiralWaveformParamsLookupPhenomXHMAmpInterpolMB(lalParams);
   #if DEBUG == 1
   printf("\n***** MBAND = %i, resTest = %.16f, ampIntorder = %i\n", MBAND, resTest, ampinterpolorder);
@@ -661,8 +687,7 @@ int IMRPhenomXHMMultiBandOneMode(
     printf("fDAMP = %e\n",pWFHM->fDAMP);
     printf("alphaL = %.16e", pPhase->alphaL);
     #endif
-    dfmerger = deltaF_mergerBin(pWFHM->fDAMP, pPhase->alphaL, resTest);
-    dfringdown = deltaF_ringdownBin(pWFHM->fDAMP, pPhase->alphaL, pAmp->lambda/(pAmp->sigma*pWFHM->fDAMP), resTest);
+    deltaF_MergerRingdown(&dfmerger, &dfringdown, resTest, pWFHM, pAmp, pPhase);
   }
 
   /* Allocate memory for the list of grids. The number of grids must be less than lengthallGrids. */
@@ -813,8 +838,8 @@ int IMRPhenomXHMMultiBandOneMode(
     double linb=IMRPhenomX_TimeShift_22(pPhase22, pWF);
 
     // Calculate IMRPhenomX phase at reference frequency
-    REAL8 phiref22 = -1./pWF->eta*IMRPhenomX_Phase_22(pWF->MfRef, &powers_of_MfRef, pPhase22, pWF) - linb*pWF->MfRef - lina + 2.0*pWF->phi0 + LAL_PI_4;
 
+    REAL8  phiref22 = -1./pWF->eta*IMRPhenomX_Phase_22(pWF->MfRef, &powers_of_MfRef, pPhase22, pWF) - linb*pWF->MfRef - lina + 2.0*pWF->phi0 + LAL_PI_4;
 
     for(UINT4 kk = 0; kk < (coarseFreqs)->length; kk++){
       REAL8 Mff = coarseFreqs->data[kk]*pWF->M_sec;
@@ -1299,6 +1324,7 @@ int IMRPhenomXHMMultiBandOneModeMixing(
 
   /* Threshold for the Multibanding. It is a measure of how restrictive it is. Smaller value implies stronger restriction, more points where evaluate the model. */
   REAL8 resTest  = XLALSimInspiralWaveformParamsLookupPhenomXHMThresholdMband(lalParams);
+  XLAL_CHECK(resTest > 0, XLAL_EDOM, "Multibanding threshold must be > 0.");
   UINT4 ampinterpolorder = XLALSimInspiralWaveformParamsLookupPhenomXHMAmpInterpolMB(lalParams);
   #if DEBUG == 1
   printf("\n***** MBAND = %i, resTest = %.16f, ampIntorder = %i\n", MBAND, resTest, ampinterpolorder);
@@ -1319,7 +1345,7 @@ int IMRPhenomXHMMultiBandOneModeMixing(
   IMRPhenomXPhaseCoefficients *pPhase22 = (IMRPhenomXPhaseCoefficients *) XLALMalloc(sizeof(IMRPhenomXPhaseCoefficients));
   IMRPhenomXGetPhaseCoefficients(pWF, pPhase22);
   //IMRPhenomX_Phase_22_ConnectionCoefficients(pWF,pPhase22);//ceci where should this go? discontinuity
-
+  
   /* Allocate and initialize the PhenomXHM lm amplitude coefficients struct */
   IMRPhenomXHMAmpCoefficients *pAmp = (IMRPhenomXHMAmpCoefficients*)XLALMalloc(sizeof(IMRPhenomXHMAmpCoefficients));
   IMRPhenomXHMPhaseCoefficients *pPhase = (IMRPhenomXHMPhaseCoefficients*)XLALMalloc(sizeof(IMRPhenomXHMPhaseCoefficients));
@@ -1335,8 +1361,7 @@ int IMRPhenomXHMMultiBandOneModeMixing(
   IMRPhenomXHM_GetAmplitudeCoefficients(pAmp, pPhase, pAmp22, pPhase22, pWFHM, pWF);
   IMRPhenomXHM_GetPhaseCoefficients(pAmp, pPhase, pAmp22, pPhase22, pWFHM, pWF,lalParams);
 
-  dfmerger = deltaF_mergerBin(pWFHM->fDAMP, pPhase->alphaL_S, resTest);
-  dfringdown = deltaF_ringdownBin(pWFHM->fDAMP, pPhase->alphaL_S, pAmp->lambda/(pAmp->sigma*pWFHM->fDAMP), resTest);
+  deltaF_MergerRingdown(&dfmerger, &dfringdown, resTest, pWFHM, pAmp, pPhase);
 
   #if DEBUG == 1
   printf("f_min = %.6f, Mfmin = %.6f\n", pWF->fMin, Mfmin);
@@ -1548,7 +1573,7 @@ int IMRPhenomXHMMultiBandOneModeMixing(
   REAL8FrequencySeries *amplitude, *phase;
   REAL8FrequencySeries *phaseSS, *amplitudeSS;
 
-
+  
   if(lencoarseS > ampinterpolorder){
     IMRPhenomXHM_Phase(&phase, coarseFreqsS, pWF, pAmp22, pPhase22, pWFHM, pAmp, pPhase);
     IMRPhenomXHM_Amplitude(&amplitude, coarseFreqsS, pWF, pAmp22, pPhase22, pWFHM, pAmp, pPhase);
@@ -1755,7 +1780,10 @@ int IMRPhenomXHMMultiBandOneModeMixing(
           Omega = (ILphaselmSS[jdx] - ILphaselmSS[jdx - 1])/(IntLawpoints[pointsPrecessedSoFar + j] - IntLawpoints[pointsPrecessedSoFar + j -1]);
         }
 
-        if(Mfhere > pAmp->fAmpMatchIM && RDcutMax < 1){
+        if(pWFHM->IMRPhenomXHMReleaseVersion == 122019 && Mfhere > pAmp->fAmpMatchIM && RDcutMax < 1){
+          RDcutMax = count;
+        }
+        if(pWFHM->IMRPhenomXHMReleaseVersion != 122019 && Mfhere > MfRDcutMax && RDcutMax < 1){
           RDcutMax = count;
         }
       }
@@ -1949,7 +1977,8 @@ int IMRPhenomXHMMultiBandOneModeMixing(
     //COMPLEX16 wf22 = htilde22->data->data[idx + offset];
     COMPLEX16 wf22 = htilde22tmp->data->data[idx - RDcutMin];
     //32 waveform in spheroidal
-    REAL8 amplm = fineAmpSS[idx-RDcutMin] * (powers_of_f.m_seven_sixths*pWFHM->Amp0);
+    REAL8 amplm = fineAmpSS[idx-RDcutMin] * pWFHM->Amp0;
+    if (pWFHM->IMRPhenomXHMRingdownAmpVersion == 0) amplm *= powers_of_f.m_seven_sixths;
     COMPLEX16 expphilm = expphi[idx];
     //Rotation to spherical with Berti's coefficients
     shift32 = linear32[idx-RDcutMin];
@@ -1959,13 +1988,23 @@ int IMRPhenomXHMMultiBandOneModeMixing(
     // Use spheroidal phase but spherical amplitude
     if(Mf < pAmp->fAmpMatchIM){
       data = sphericalWF_32/cabs(sphericalWF_32) * fineAmp[idx];
-      ((*htildelm)->data->data)[idx + offset] = data * minus1l;
+    }
+    // Use spheroidal amp but spherical phase. Case when fAmpMatchIM < fPhaseMatchIM.
+    // For the 122019 release the phase freq was always lower than the amp freq so this case was not necessary
+    // In fact, that is not completely true, in IMRPhenomXHM_Intermediate_CollocPtsFreqs the phase cutting freq for the 122019 is pushed
+    // to higher frequencies for EMRI and negative s1z and it can be higher than the cutting freq for the amplitude.
+    // In that case, the 122019 release extrapolated the spheroidal phase to lower frequencies.
+    else if(Mf < pPhase->fPhaseMatchIM && pWFHM->IMRPhenomXHMReleaseVersion != 122019){
+      // This part does not use Multibanding for the phase. The spherical phase is only interpolated up to RDcutMin (fAmpMatchIM)
+      // This is not using Multibanding for the phase. The spherical phase is only interpolated up to RDcutMin (fAmpMatchIM)
+      COMPLEX16 myphase = cexp(I * IMRPhenomXHM_Phase_ModeMixing(&powers_of_f, pAmp, pPhase, pWFHM, pAmp22, pPhase22, pWF));
+      data = cabs(sphericalWF_32) * myphase;
     }
     // Use spheroidal amplitude and phase
     else{
       data = sphericalWF_32;
-      ((*htildelm)->data->data)[idx + offset] = data * minus1l;
     }
+    ((*htildelm)->data->data)[idx + offset] = data * minus1l;
     #if DEBUG == 1
     data = ((*htildelm)->data->data)[idx + offset];
     fprintf(file6, "%.16f  %.16e %.16e\n",(idx + offset)*deltaF, creal(data), cimag(data));
@@ -2179,7 +2218,7 @@ static int interpolateAmplitudeMixing(
 static int SetupWFArraysReal(
   REAL8Sequence **freqs,           /**<[out] Frequency array to evaluate model **/
   REAL8FrequencySeries **amphase,  /**<[out] Initialize amplitude or phase with the length of freqs **/
-  REAL8Sequence *freqs_In,         /**< Input frequency array or fmin, fmax **/
+  const REAL8Sequence *freqs_In,         /**< Input frequency array or fmin, fmax **/
   IMRPhenomXWaveformStruct *pWF,   /**< Structure of the 22 mode **/
   LIGOTimeGPS ligotimegps_zero     /**< Needed to initialize amphase **/
 ){
@@ -2294,7 +2333,7 @@ static int SetupWFArraysReal(
 /* Spherical amplitude evaluated in an input frequency array */
 static int IMRPhenomXHM_Amplitude(
   REAL8FrequencySeries **amplm,           /**<[out] amplitude of hlm mode **/
-  REAL8Sequence *freqs_In,                /**< Frequency array to evaluate model or fmin, fmax  **/
+  const REAL8Sequence *freqs_In,                /**< Frequency array to evaluate model or fmin, fmax  **/
   IMRPhenomXWaveformStruct *pWF,          /**< Structure of the 22 mode **/
   IMRPhenomXAmpCoefficients *pAmp22,      /**< Amplitude coefficients 22 */
   IMRPhenomXPhaseCoefficients *pPhase22,  /**< Phase coefficients 22 */
@@ -2342,7 +2381,7 @@ static int IMRPhenomXHM_Amplitude(
         }
         else
         {
-          amp = IMRPhenomXHM_Amplitude_ModeMixing(Mf, &powers_of_Mf, pAmp, pPhase, pWFHM, pAmp22, pPhase22, pWF);
+          amp = IMRPhenomXHM_Amplitude_ModeMixing(&powers_of_Mf, pAmp, pPhase, pWFHM, pAmp22, pPhase22, pWF);
           /* Reconstruct waveform: h(f) = A(f) * Exp[I phi(f)] */
           ((*amplm)->data->data)[idx+offset] = pWFHM->Amp0 * amp;
         }
@@ -2360,7 +2399,7 @@ static int IMRPhenomXHM_Amplitude(
         }
         else
         {
-          amp = IMRPhenomXHM_Amplitude_noModeMixing(Mf, &powers_of_Mf, pAmp, pWFHM);
+          amp = IMRPhenomXHM_Amplitude_noModeMixing(&powers_of_Mf, pAmp, pWFHM);
           /* Reconstruct waveform: h(f) = A(f) * Exp[I phi(f)] */
           ((*amplm)->data->data)[idx+offset] = pWFHM->Amp0 * amp;
         }
@@ -2377,7 +2416,7 @@ static int IMRPhenomXHM_Amplitude(
 /* Ringdown amplitude ansatz evaluated in an input frequency array */
 static int IMRPhenomXHM_AmplitudeMixing(
   REAL8FrequencySeries **amplm,           /**<[out] amplitude of hlm mode **/
-  REAL8Sequence *freqs_In,                /**< Frequency array to evaluate model or fmin, fmax  **/
+  const REAL8Sequence *freqs_In,                /**< Frequency array to evaluate model or fmin, fmax  **/
   IMRPhenomXWaveformStruct *pWF,          /**< Structure of the 22 mode **/
   IMRPhenomXHMWaveformStruct *pWFHM,      /**< waveform parameters lm mode */
   IMRPhenomXHMAmpCoefficients *pAmp,      /**< Amplitude coefficients lm */
@@ -2402,6 +2441,7 @@ static int IMRPhenomXHM_AmplitudeMixing(
   printf("\n\nfstart, fend = %.16f %.16f\n\n", freqs->data[0], freqs->data[freqs->length-1]);
   #endif
 
+
   /* Loop over frequencies to generate waveform */
   if(pWFHM->Ampzero==0){
     IMRPhenomX_UsefulPowers powers_of_Mf;
@@ -2420,7 +2460,8 @@ static int IMRPhenomXHM_AmplitudeMixing(
       }
       else
       {
-        amp = IMRPhenomXHM_RD_Amp_Ansatz(powers_of_Mf.itself, pWFHM, pAmp);
+        amp = IMRPhenomXHM_RD_Amp_Ansatz(&powers_of_Mf, pWFHM, pAmp);
+        if (pWFHM->IMRPhenomXHMRingdownAmpVersion == 0) amp *= pWF->ampNorm;
         /* Reconstruct waveform: h(f) = A(f) * Exp[I phi(f)] */
         ((*amplm)->data->data)[idx+offset] =  amp;
       }
@@ -2436,7 +2477,7 @@ static int IMRPhenomXHM_AmplitudeMixing(
 /* Spherical phase evaluated in an input frequency array */
 static int IMRPhenomXHM_Phase(
   REAL8FrequencySeries **phaselm,         /**<[out] phase of hlm mode **/
-  REAL8Sequence *freqs_In,                /**< Frequency array to evaluate model or fmin, fmax  **/
+  const REAL8Sequence *freqs_In,                /**< Frequency array to evaluate model or fmin, fmax  **/
   IMRPhenomXWaveformStruct *pWF,          /**< Structure of the 22 mode **/
   IMRPhenomXAmpCoefficients *pAmp22,      /**< Amplitude coefficients 22 */
   IMRPhenomXPhaseCoefficients *pPhase22,  /**< Phase coefficients 22 */
@@ -2492,7 +2533,7 @@ static int IMRPhenomXHM_Phase(
           }
           else
           {
-            phi = IMRPhenomXHM_Phase_ModeMixing(Mf, &powers_of_Mf, pAmp, pPhase, pWFHM, pAmp22, pPhase22, pWF);
+            phi = IMRPhenomXHM_Phase_ModeMixing(&powers_of_Mf, pAmp, pPhase, pWFHM, pAmp22, pPhase22, pWF);
             /* Only the first coarse point in the RD needs the unwrapping.
             If we remove the enter condition we would get a nice and smooth coarse phase up to pAmp->fAmpMatchIM. */
             if(Mf > pPhase->fPhaseMatchIM && idx>0 && enter == 1){
@@ -2524,7 +2565,7 @@ static int IMRPhenomXHM_Phase(
         }
         else
         {
-          phi = IMRPhenomXHM_Phase_noModeMixing(Mf, &powers_of_Mf, pPhase, pWFHM, pWF);
+          phi = IMRPhenomXHM_Phase_noModeMixing(&powers_of_Mf, pPhase, pWFHM, pWF);
           /* Reconstruct waveform: h(f) = A(f) * Exp[I phi(f)] */
           ((*phaselm)->data->data)[idx+offset] = phi;
         }
@@ -2541,7 +2582,7 @@ static int IMRPhenomXHM_Phase(
 /* Ringdown phase ansatz evaluated in an input frequency array */
 static int IMRPhenomXHM_PhaseMixing(
   REAL8FrequencySeries **phaselm,         /**<[out] phase of hlm mode **/
-  REAL8Sequence *freqs_In,                /**< Frequency array to evaluate model or fmin, fmax  **/
+  const REAL8Sequence *freqs_In,                /**< Frequency array to evaluate model or fmin, fmax  **/
   IMRPhenomXWaveformStruct *pWF,          /**< Structure of the 22 mode **/
   IMRPhenomXHMWaveformStruct *pWFHM,      /**< waveform parameters lm mode */
   IMRPhenomXHMPhaseCoefficients *pPhase  /**< Phase coefficients 22 */
diff --git a/lalsimulation/lib/LALSimIMRPhenomXHM_multiband.h b/lalsimulation/lib/LALSimIMRPhenomXHM_multiband.h
index 13a662142d85f2e3185d2703bbaf7a0e0daf7830..e59f6b68e8afa492c2e9e1f275cc3047337f9a23 100644
--- a/lalsimulation/lib/LALSimIMRPhenomXHM_multiband.h
+++ b/lalsimulation/lib/LALSimIMRPhenomXHM_multiband.h
@@ -54,7 +54,7 @@ int IMRPhenomXHMMultiBandOneModeMixing(
 static int SetupWFArraysReal(
   REAL8Sequence **freqs,           /**<[out] Frequency array to evaluate model **/
   REAL8FrequencySeries **amphase,  /**<[out] Initialize amplitude or phase with the length of freqs **/
-  REAL8Sequence *freqs_In,         /**< Input frequency array or fmin, fmax **/
+  const REAL8Sequence *freqs_In,         /**< Input frequency array or fmin, fmax **/
   IMRPhenomXWaveformStruct *pWF,   /**< Structure of the 22 mode **/
   LIGOTimeGPS ligotimegps_zero     /**< Needed to initialize amphase **/
 );
@@ -63,7 +63,7 @@ static int SetupWFArraysReal(
 
 static int IMRPhenomXHM_Amplitude(
   REAL8FrequencySeries **amplm,           /**<[out] amplitude of hlm mode **/
-  REAL8Sequence *freqs_In,                /**< Frequency array to evaluate model or fmin, fmax  **/
+  const REAL8Sequence *freqs_In,                /**< Frequency array to evaluate model or fmin, fmax  **/
   IMRPhenomXWaveformStruct *pWF,          /**< Structure of the 22 mode **/
   IMRPhenomXAmpCoefficients *pAmp22,      /**< Amplitude coefficients 22 */
   IMRPhenomXPhaseCoefficients *pPhase22,  /**< Phase coefficients 22 */
@@ -74,7 +74,7 @@ static int IMRPhenomXHM_Amplitude(
 
 static int IMRPhenomXHM_AmplitudeMixing(
   REAL8FrequencySeries **amplm,           /**<[out] amplitude of hlm mode **/
-  REAL8Sequence *freqs_In,                /**< Frequency array to evaluate model or fmin, fmax  **/
+  const REAL8Sequence *freqs_In,                /**< Frequency array to evaluate model or fmin, fmax  **/
   IMRPhenomXWaveformStruct *pWF,          /**< Structure of the 22 mode **/
   IMRPhenomXHMWaveformStruct *pWFHM,      /**< waveform parameters lm mode */
   IMRPhenomXHMAmpCoefficients *pAmp,      /**< Amplitude coefficients lm */
@@ -83,7 +83,7 @@ static int IMRPhenomXHM_AmplitudeMixing(
 
 static int IMRPhenomXHM_Phase(
   REAL8FrequencySeries **phaselm,         /**<[out] phase of hlm mode **/
-  REAL8Sequence *freqs_In,                /**< Frequency array to evaluate model or fmin, fmax  **/
+  const REAL8Sequence *freqs_In,                /**< Frequency array to evaluate model or fmin, fmax  **/
   IMRPhenomXWaveformStruct *pWF,          /**< Structure of the 22 mode **/
   IMRPhenomXAmpCoefficients *pAmp22,      /**< Amplitude coefficients 22 */
   IMRPhenomXPhaseCoefficients *pPhase22,  /**< Phase coefficients 22 */
@@ -94,7 +94,7 @@ static int IMRPhenomXHM_Phase(
 
 static int IMRPhenomXHM_PhaseMixing(
   REAL8FrequencySeries **phaselm,         /**<[out] phase of hlm mode **/
-  REAL8Sequence *freqs_In,                /**< Frequency array to evaluate model or fmin, fmax  **/
+  const REAL8Sequence *freqs_In,                /**< Frequency array to evaluate model or fmin, fmax  **/
   IMRPhenomXWaveformStruct *pWF,          /**< Structure of the 22 mode **/
   IMRPhenomXHMWaveformStruct *pWFHM,      /**< waveform parameters lm mode */
   IMRPhenomXHMPhaseCoefficients *pPhase   /**< Phase coefficients 22 */
@@ -175,6 +175,8 @@ static int interpolateAmplitudeMixing(
 static double deltaF_mergerBin(REAL8 fdamp, REAL8 alpha4, REAL8 abserror);
 static double deltaF_ringdownBin(REAL8 fdamp, REAL8 alpha4, REAL8 LAMBDA, REAL8 abserror);
 
+INT4 deltaF_MergerRingdown(REAL8 *dfmerger, REAL8 *dfringdown, REAL8 resTest, IMRPhenomXHMWaveformStruct *pWFHM, IMRPhenomXHMAmpCoefficients *pAmp, IMRPhenomXHMPhaseCoefficients *pPhase);
+
   #ifdef __cplusplus
 }
 #endif
diff --git a/lalsimulation/lib/LALSimIMRPhenomXHM_ringdown.c b/lalsimulation/lib/LALSimIMRPhenomXHM_ringdown.c
index 941647979328eaa8a874ababb495f7badc9b0493..8c88e2f589e4d877728a1d1743ab9d688492d2ab 100644
--- a/lalsimulation/lib/LALSimIMRPhenomXHM_ringdown.c
+++ b/lalsimulation/lib/LALSimIMRPhenomXHM_ringdown.c
@@ -40,151 +40,224 @@
 
 // alambda, lambda and sigma are the coefficients of the ringdown ansatz, see Eq. (6.2)
 
+/* Start of Amp Parameter Space Fits */
 
-static double IMRPhenomXHM_RD_Amp_21_alambda(double eta, double S, double chi1, double chi2, int RDAmpFlag) {
-    UNUSED double total=0, delta=sqrt(1. - 4.*eta),eta2,eta3,eta4,S2,S3;
+
+static double IMRPhenomXHM_RD_Amp_21_alambda(IMRPhenomXWaveformStruct *pWF, int RDAmpFlag) {
+    double total=0;
     switch (RDAmpFlag){
         case 122018:{
+            double eta = pWF->eta;
+            double S = pWF->STotR;
+            double delta=sqrt(1.-4.*eta),eta2,S2;
             eta2 = pow(eta,2);
-            eta3 = pow(eta,3);
-            eta4 = pow(eta,4);
             S2 = pow(S,2);
-            S3 = pow(S,3);
             double noSpin = sqrt(eta - 4.*eta2)*(0.00734983387668636 - 0.0012619735607202085*eta + 0.01042318959002753*eta2);
             double eqSpin = sqrt(eta - 4.*eta2)*S*(-0.004839645742570202 - 0.0013927779195756036*S + eta2*(-0.054621206928483663 + 0.025956604949552205*S + 0.020360826886107204*S2));
-            double uneqSpin = -0.018115657394753674*(chi1 - 1.*chi2)*eta2*(1. - 10.539795474715346*eta2*delta);
+            double uneqSpin = -0.018115657394753674*pWF->dchi*eta2*(1. - 10.539795474715346*eta2*delta);
             total = noSpin + eqSpin + uneqSpin;
             break;
         }
-        default:{XLAL_ERROR_REAL8(XLAL_EINVAL,"Error in IMRPhenomXHM_RD_Amp_21_a: version is not valid. Recommended version is 122018.");}
+        case 122022:{
+            double eta = pWF->eta;
+            double delta = pWF->delta;
+            double S = pWF->chiPNHat;
+            double chidiff = pWF->dchi_half;
+            double eta1 = eta;
+            double eta2 = eta1 * eta1;
+            double eta3 = eta1 * eta2;
+            double eta4 = eta1 * eta3;
+            double eta5 = eta1 * eta4;
+            double S1 = S;
+            double S2 = S1 * S1;
+            double chidiff1 = chidiff;
+            total = fabs(delta*(0.24548180919287976 - 0.25565119457386487*eta1)*eta1 + chidiff1*delta*eta1*(0.5670798742968471*eta1 - 14.276514548218454*eta2 + 45.014547333879136*eta3) + chidiff1*delta*eta1*(0.4580805242442763*eta1 - 4.859294663135058*eta2 + 14.995447609839573*eta3)*S1 + chidiff1*eta5*(-27.031582936285528 + 6.468164760468401*S1 + 0.34222101136488015*S2) + delta*eta1*S1*(-0.2204878224611389*(1.0730799832007898 - 3.44643820338605*eta1 + 32.520429274459836*eta2 - 83.21097158567372*eta3) + 0.008901444811471891*(-5.876973170072921 + 120.70115519895002*eta1 - 916.5281661566283*eta2 + 2306.8425350489847*eta3)*S1 + 0.015541783867953005*(2.4780170686140455 + 17.377013149762398*eta1 - 380.91157168170236*eta2 + 1227.5332509075172*eta3)*S2));
+            break;
+        }
+        default:{XLAL_ERROR_REAL8(XLAL_EINVAL,"Error in IMRPhenomXHM_RD_Amp_21_alambda: version %i is not valid.", RDAmpFlag);}
     }
     return total;
 }
 
-static double IMRPhenomXHM_RD_Amp_21_lambda(double eta, double S, double chi1, double chi2, int RDAmpFlag) {
-    UNUSED double total=0, delta=sqrt(1. - 4.*eta),eta2,S2;
+static double IMRPhenomXHM_RD_Amp_21_lambda(IMRPhenomXWaveformStruct *pWF, int RDAmpFlag) {
+    double total=0;
     switch (RDAmpFlag){
         case 122018:{
+            double eta = pWF->eta;
+            double S = pWF->STotR;
+            double delta=sqrt(1.-4.*eta), eta2;
             eta2 = pow(eta,2);
-            S2 = pow(S,2);
             double noSpin = 0.5566284518926176 + 0.12651770333481904*eta + 1.8084545267208734*eta2;
             double eqSpin = (0.29074922226651545 + eta2*(-2.101111399437034 - 3.4969956644617946*S) + eta*(0.059317243606471406 - 0.31924748117518226*S) + 0.27420263462336675*S)*S;
-            double uneqSpin = 1.0122975748481835*(chi1 - 1.*chi2)*eta2*delta;
+            double uneqSpin = 1.0122975748481835*pWF->dchi*eta2*delta;
             total = noSpin + eqSpin + uneqSpin;
             break;
         }
-        default:{XLAL_ERROR_REAL8(XLAL_EINVAL,"Error in IMRPhenomXHM_RD_Amp_21_lambda: version is not valid. Recommended version is 122018.");}
+        case 122022:{
+            double eta = pWF->eta;
+            double S = pWF->chiPNHat;
+            double chidiff = pWF->dchi_half;
+            double eta1 = eta;
+            double eta2 = eta1 * eta1;
+            double eta3 = eta1 * eta2;
+            double eta4 = eta1 * eta3;
+            double S1 = S;
+            double chidiff1 = chidiff;
+            total = fabs(1.0092933052569775 - 0.2791855444800297*eta1 + 1.7110615047319937*eta2 + chidiff1*(-0.1054835719277311*eta1 + 7.506083919925026*eta2 - 30.1595680078279*eta3) + chidiff1*(2.078267611384239*eta1 - 10.166026002515457*eta2 - 1.2091616330625208*eta3)*S1 + S1*(0.17250873250247642*(1.0170226856985174 + 1.0395650952176598*eta1 - 35.73623734051525*eta2 + 403.68074286921444*eta3 - 1194.6152711219886*eta4) + 0.06850746964805364*(1.507796537056924 + 37.81075363806507*eta1 - 863.117144661059*eta2 + 6429.543634627373*eta3 - 15108.557419182316*eta4)*S1));
+            break;
+        }
+        default:{XLAL_ERROR_REAL8(XLAL_EINVAL,"Error in IMRPhenomXHM_RD_Amp_21_lambda: version %i is not valid.", RDAmpFlag);}
     }
     return total;
 }
 
-static double IMRPhenomXHM_RD_Amp_33_alambda(double eta, double S, double chi1, double chi2, int RDAmpFlag) {
-  UNUSED double total=0,eta2,eta3,eta4,eta5,eta6,S2,delta=sqrt(1-4*eta);
+static double IMRPhenomXHM_RD_Amp_33_alambda(IMRPhenomXWaveformStruct *pWF, int RDAmpFlag) {
+  double total=0;
   switch (RDAmpFlag){
     case 122018:{
+      double eta = pWF->eta;
+      double S = pWF->STotR;
+      double eta2,eta4,delta=sqrt(1-4*eta);
       eta2 = pow(eta,2);
-      eta3 = pow(eta,3);
       eta4 = pow(eta,4);
-      eta5 = pow(eta,5);
-      eta6 = pow(eta,6);
-      S2 = pow(S,2);
       double noSpin = sqrt(eta - 4.*eta2)*(0.013700854227665184 + 0.01202732427321774*eta + 0.0898095508889557*eta2);
       double eqSpin = sqrt(eta - 4.*eta2)*(0.0075858980586079065 + eta*(-0.013132320758494439 - 0.018186317026076343*S) + 0.0035617441651710473*S)*S;
-      double uneqSpin = eta4*(chi2*(-0.09802218411554885 - 0.05745949361626237*S) + chi1*(0.09802218411554885 + 0.05745949361626237*S) + eta2*(chi1*(-4.2679864481479886 - 11.877399902871485*S) + chi2*(4.2679864481479886 + 11.877399902871485*S))*delta);
+      double uneqSpin = eta4*(pWF->chi2L*(-0.09802218411554885 - 0.05745949361626237*S) + pWF->chi1L*(0.09802218411554885 + 0.05745949361626237*S) + eta2*(pWF->chi1L*(-4.2679864481479886 - 11.877399902871485*S) + pWF->chi2L*(4.2679864481479886 + 11.877399902871485*S))*delta);
       total = noSpin + eqSpin + uneqSpin;
       break;
     }
-    default:{XLAL_ERROR_REAL8(XLAL_EINVAL,"Error in IMRPhenomXHM_RD_Amp_33_alambda: version is not valid. Recommended version is 122018.");}
+    default:{XLAL_ERROR_REAL8(XLAL_EINVAL,"Error in IMRPhenomXHM_RD_Amp_33_alambda: version %i is not valid.", RDAmpFlag);}
   }
   return total;
 }
 
-static double IMRPhenomXHM_RD_Amp_33_lambda(double eta, double S, double chi1, double chi2, int RDAmpFlag) {
-  UNUSED double total=0,eta2,S2,S3,delta=sqrt(1-4*eta);
+static double IMRPhenomXHM_RD_Amp_33_lambda(IMRPhenomXWaveformStruct *pWF, int RDAmpFlag) {
+  double total=0;
   switch (RDAmpFlag){
     case 122018:{
+      double eta = pWF->eta;
+      double S = pWF->STotR;
+      double eta2,S2,delta=sqrt(1-4*eta);
       eta2 = pow(eta,2);
       S2 = pow(S,2);
-      S3 = pow(S,3);
       double noSpin = 0.7435306475478924 - 0.06688558533374556*eta + 1.471989765837694*eta2;
       double eqSpin = S*(0.19457194111990656 + 0.07564220573555203*S + eta*(-0.4809350398289311 + 0.17261430318577403*S - 0.1988991467974821*S2));
-      double uneqSpin = 1.8881959341735146*(chi1 - 1.*chi2)*eta2*delta;
+      double uneqSpin = 1.8881959341735146*pWF->dchi*eta2*delta;
       total = noSpin + eqSpin + uneqSpin;
       break;
     }
-    default:{XLAL_ERROR_REAL8(XLAL_EINVAL,"Error in IMRPhenomXHM_RD_Amp_33_lambda: version is not valid. Recommended version is 122018.");}
+    default:{XLAL_ERROR_REAL8(XLAL_EINVAL,"Error in IMRPhenomXHM_RD_Amp_33_lambda: version %i is not valid.", RDAmpFlag);}
   }
   return total;
 }
 
-static double IMRPhenomXHM_RD_Amp_32_alambda(double eta, double S, double chi1, double chi2, int RDAmpFlag) {
-  UNUSED double total=0,eta2,eta3,eta4,eta5,eta6,eta7,eta8,eta9,S2;
+static double IMRPhenomXHM_RD_Amp_32_alambda(IMRPhenomXWaveformStruct *pWF, int RDAmpFlag) {
+  double total=0;
   switch (RDAmpFlag){
-    case 122018:{
-      eta2 = pow(eta,2);
-      eta3 = pow(eta,3);
-      eta4 = pow(eta,4);
-      eta5 = pow(eta,5);
-      eta6 = pow(eta,6);
-      eta7 = pow(eta,7);
-      eta8 = pow(eta,8);
-      eta9 = pow(eta,9);
-      S2 = pow(S,2);
-      double noSpin = 0.00012587900257140724 + 0.03927886286971654*eta - 0.8109309606583066*eta2 + 8.820604907164254*eta3 - 51.43344812454074*eta4 + 141.81940900657446*eta5 - 140.0426973304466*eta6;
-      double eqSpin = S*(-0.00006001471234796344 + eta4*(-0.7849112300598181 - 2.09188976953315*S) + eta2*(0.08311497969032984 - 0.15569578955822236*S) + eta*(-0.01083175709906557 + 0.00568899459837252*S) - 0.00009363591928190229*S + 1.0670798489407887*eta3*S);
-      double uneqSpin = -0.04537308968659669*pow(chi1 - 1.*chi2,2)*eta2*(1. - 8.711096029480697*eta + 18.362371966229926*eta2) + (chi1 - 1.*chi2)*(-297.36978685672733 + 3103.2516759087644*eta - 10001.774055779177*eta2 + 9386.734883473799*eta3)*eta6;
-      total = noSpin + eqSpin + uneqSpin;
-      break;
-    }
-    default:{XLAL_ERROR_REAL8(XLAL_EINVAL,"Error in IMRPhenomXHM_RD_Amp_32_alambda: version is not valid. Recommended version is 122018.");}
+      case 122018:{
+        double eta = pWF->eta;
+        double S = pWF->STotR;
+        double eta2,eta3,eta4,eta5,eta6;
+        eta2 = pow(eta,2);
+        eta3 = pow(eta,3);
+        eta4 = pow(eta,4);
+        eta5 = pow(eta,5);
+        eta6 = pow(eta,6);
+        double noSpin = 0.00012587900257140724 + 0.03927886286971654*eta - 0.8109309606583066*eta2 + 8.820604907164254*eta3 - 51.43344812454074*eta4 + 141.81940900657446*eta5 - 140.0426973304466*eta6;
+        double eqSpin = S*(-0.00006001471234796344 + eta4*(-0.7849112300598181 - 2.09188976953315*S) + eta2*(0.08311497969032984 - 0.15569578955822236*S) + eta*(-0.01083175709906557 + 0.00568899459837252*S) - 0.00009363591928190229*S + 1.0670798489407887*eta3*S);
+        double uneqSpin = -0.04537308968659669*pow(pWF->dchi,2)*eta2*(1. - 8.711096029480697*eta + 18.362371966229926*eta2) + pWF->dchi*(-297.36978685672733 + 3103.2516759087644*eta - 10001.774055779177*eta2 + 9386.734883473799*eta3)*eta6;
+        total = noSpin + eqSpin + uneqSpin;
+        break;
+      }
+        case 122022:{
+            double eta = pWF->eta;
+            double delta = pWF->delta;
+            double S = pWF->STotR;
+            double chidiff = pWF->dchi_half;
+            double eta1 = eta;
+            double eta2 = eta1 * eta1;
+            double eta3 = eta1 * eta2;
+            double eta4 = eta1 * eta3;
+            double eta5 = eta1 * eta4;
+            double eta6 = eta1 * eta5;
+            double S1 = S;
+            double S2 = S1 * S1;
+            double chidiff1 = chidiff;
+            double chidiff2 = chidiff1 * chidiff1;
+            total = chidiff2*(-3.4614418482110163*eta3 + 35.464117772624164*eta4 - 85.19723511005235*eta5) + chidiff1*delta*(2.0328561081997463*eta3 - 46.18751757691501*eta4 + 170.9266105597438*eta5) + chidiff2*(-0.4600401291210382*eta3 + 12.23450117663151*eta4 - 42.74689906831975*eta5)*S1 + chidiff1*delta*(5.786292428422767*eta3 - 53.60467819078566*eta4 + 117.66195692191727*eta5)*S1 + S1*(-0.0013330716557843666*(56.35538385647113*eta1 - 1218.1550992423377*eta2 + 16509.69605686402*eta3 - 102969.88022112886*eta4 + 252228.94931931415*eta5 - 150504.2927996263*eta6) + 0.0010126460331462495*(-33.87083889060834*eta1 + 502.6221651850776*eta2 - 1304.9210590188136*eta3 - 36980.079328277505*eta4 + 295469.28617550555*eta5 - 597155.7619486618*eta6)*S1 - 0.00043088431510840695*(-30.014415072587354*eta1 - 1900.5495690280086*eta2 + 76517.21042363928*eta3 - 870035.1394696251*eta4 + 3.9072674134789007e6*eta5 - 6.094089675611567e6*eta6)*S2) + (0.08408469319155859*eta1 - 1.223794846617597*eta2 + 6.5972460654253515*eta3 - 15.707327897569396*eta4 + 14.163264397061505*eta5)*pow(1 - 8.612447115134758*eta1 + 18.93655612952139*eta2,-1);
+            break;
+        }
+        default:{XLAL_ERROR_REAL8(XLAL_EINVAL,"Error in IMRPhenomXHM_RD_Amp_32_alambda: version %i is not valid.", RDAmpFlag);}
   }
   return total;
 }
 
-static double IMRPhenomXHM_RD_Amp_32_lambda(double eta, double S, double chi1, double chi2, int RDAmpFlag) {
-  UNUSED double total=0,eta2,eta3,S2,delta=sqrt(1.-4*eta);
+static double IMRPhenomXHM_RD_Amp_32_lambda(IMRPhenomXWaveformStruct *pWF, int RDAmpFlag) {
+  double total=0;
   switch (RDAmpFlag){
     case 122018:{
+      double eta = pWF->eta;
+      double S = pWF->STotR;
+      double eta2,eta3,delta=sqrt(1.-4*eta);
       eta2 = pow(eta,2);
       eta3 = pow(eta,3);
-      S2 = pow(S,2);
       double noSpin = (sqrt(1. - 3.*eta)*(0.0341611244787871 - 0.3197209728114808*eta + 0.7689553234961991*eta2))/(0.048429644168112324 - 0.43758296068790314*eta + eta2);
       double eqSpin = sqrt(1. - 3.*eta)*S*(0.11057199932233873 + eta2*(25.536336676250748 - 71.18182757443142*S) + 9.790509295728649*eta*S + eta3*(-56.96407763839491 + 175.47259563543165*S));
-      double uneqSpin = -5.002106168893265*pow(chi1 - 1.*chi2,2)*eta2*delta;
+      double uneqSpin = -5.002106168893265*pow(pWF->dchi,2)*eta2*delta;
       total = noSpin + eqSpin + uneqSpin;
       break;
     }
-    default:{XLAL_ERROR_REAL8(XLAL_EINVAL,"Error in IMRPhenomXHM_RD_Amp_32_lambda: version is not valid. Recommended version is 122018.");}
+          case 122022:{
+            double eta = pWF->eta;
+            double delta = pWF->delta;
+            double S = pWF->STotR;
+            double chidiff = pWF->dchi_half;
+            double eta1 = eta;
+            double eta2 = eta1 * eta1;
+            double eta3 = eta1 * eta2;
+            double eta4 = eta1 * eta3;
+            double eta5 = eta1 * eta4;
+            double S1 = S;
+            double chidiff1 = chidiff;
+            double chidiff2 = chidiff1 * chidiff1;
+            total = 0.978510781593996 + 0.36457571743142897*eta1 - 12.259851752618998*eta2 + 49.19719473681921*eta3 + chidiff1*delta*(-188.37119473865533*eta3 + 2151.8731700399308*eta4 - 6328.182823770599*eta5) + chidiff2*(115.3689949926392*eta3 - 1159.8596972989067*eta4 + 2657.6998831179444*eta5) + S1*(0.22358643406992756*(0.48943645614341924 - 32.06682257944444*eta1 + 365.2485484044132*eta2 - 915.2489655397206*eta3) + 0.0792473022309144*(1.877251717679991 - 103.65639889587327*eta1 + 1202.174780792418*eta2 - 3206.340850767219*eta3)*S1);
+            break;
+        }
+        default:{XLAL_ERROR_REAL8(XLAL_EINVAL,"Error in IMRPhenomXHM_RD_Amp_32_lambda: version %i is not valid.", RDAmpFlag);}
   }
   return total;
 }
 
-static double IMRPhenomXHM_RD_Amp_44_alambda(double eta, double S, double chi1, double chi2, int RDAmpFlag) {
-    UNUSED double total=0, delta=sqrt(1. - 4.*eta),eta2,eta3,eta4,eta5,eta6,S2,S3;
+static double IMRPhenomXHM_RD_Amp_44_alambda(IMRPhenomXWaveformStruct *pWF, int RDAmpFlag) {
+    double total=0;
     switch (RDAmpFlag){
         case 122018:{
+            double eta = pWF->eta;
+            double S = pWF->STotR;
+            double delta=sqrt(1.-4.*eta),eta2,eta3,eta4,eta5,S2;
             eta2 = pow(eta,2);
             eta3 = pow(eta,3);
             eta4 = pow(eta,4);
             eta5 = pow(eta,5);
-            eta6 = pow(eta,6);
             S2 = pow(S,2);
-            S3 = pow(S,3);
             double noSpin = sqrt(eta - 3.*eta2)*(0.007904587819112173 + 0.09558474985614368*eta - 2.663803397359775*eta2 + 28.298192768381554*eta3 - 136.10446022757958*eta4 + 233.23167528016833*eta5);
             double eqSpin = sqrt(eta - 3.*eta2)*S*(0.0049703757209330025 + 0.004122811292229324*S + eta*(-0.06166686913913691 + 0.014107365722576927*S)*S + eta2*(-0.2945455034809188 + 0.4139026619690879*S - 0.1389170612199015*S2) + eta3*(0.9225758392294605 - 0.9656098473922222*S + 0.19708289555425246*S2) + 0.000657528128497184*S2);
-            double uneqSpin = 0.00659873279539475*(chi1 - 1.*chi2)*eta2*delta;
+            double uneqSpin = 0.00659873279539475*pWF->dchi*eta2*delta;
             total = noSpin + eqSpin + uneqSpin;
             break;
         }
-        default:{XLAL_ERROR_REAL8(XLAL_EINVAL,"Error in IMRPhenomXHM_RD_Amp_44_a: version is not valid. Recommended version is 122018.");}
+        default:{XLAL_ERROR_REAL8(XLAL_EINVAL,"Error in IMRPhenomXHM_RD_Amp_44_a: version %i is not valid.", RDAmpFlag);}
     }
     return total;
 }
 
-static double IMRPhenomXHM_RD_Amp_44_lambda(double eta, double S, double chi1, double chi2, int RDAmpFlag) {
-    UNUSED double total=0, delta=sqrt(1. - 4.*eta),eta2,eta3,eta4,eta5,eta6,eta7;
+static double IMRPhenomXHM_RD_Amp_44_lambda(IMRPhenomXWaveformStruct *pWF, int RDAmpFlag) {
+    double total=0;
     switch (RDAmpFlag){
         case 122018:{
+            double eta = pWF->eta;
+            double S = pWF->STotR;
+            double delta=sqrt(1.-4.*eta),eta2,eta3,eta4,eta5,eta6,eta7;
             eta2 = pow(eta,2);
             eta3 = pow(eta,3);
             eta4 = pow(eta,4);
@@ -193,33 +266,48 @@ static double IMRPhenomXHM_RD_Amp_44_lambda(double eta, double S, double chi1, d
             eta7 = pow(eta,7);
             double noSpin = 0.7702864948772887 + 32.81532373698395*eta - 1625.1795901450212*eta2 + 31305.458876573215*eta3 - 297375.5347399236*eta4 + 1.4726521941846698e6*eta5 - 3.616582470072637e6*eta6 + 3.4585865843680725e6*eta7;
             double eqSpin = (-0.03011582009308575*S + 0.09034746027925727*eta*S + 1.8738784391649446*eta2*S - 5.621635317494836*eta3*S)/(-1.1340218677260014 + S);
-            double uneqSpin = 0.959943270591552*pow(chi1 - 1.*chi2,2)*eta2 + 0.853573071529436*(chi1 - 1.*chi2)*eta2*delta;
+            double uneqSpin = 0.959943270591552*pow(pWF->dchi,2)*eta2 + 0.853573071529436*pWF->dchi*eta2*delta;
             total = noSpin + eqSpin + uneqSpin;
             break;
         }
-        default:{XLAL_ERROR_REAL8(XLAL_EINVAL,"Error in IMRPhenomXHM_RD_Amp_44_lambda: version is not valid. Recommended version is 122018.");}
+        default:{XLAL_ERROR_REAL8(XLAL_EINVAL,"Error in IMRPhenomXHM_RD_Amp_44_lambda: version %i is not valid.", RDAmpFlag);}
     }
     return total;
 }
 
-static double IMRPhenomXHM_RD_Amp_21_sigma(double eta, double S, double chi1, double chi2, int RDAmpFlag) {
-    UNUSED double total=0, delta=sqrt(1. - 4.*eta),eta2;
+static double IMRPhenomXHM_RD_Amp_21_sigma(IMRPhenomXWaveformStruct *pWF, int RDAmpFlag) {
+    double total=0;
     switch (RDAmpFlag){
         case 122018:{
+            double eta = pWF->eta;
+            double S = pWF->STotR;
+            double delta=sqrt(1.-4.*eta),eta2;
             eta2 = pow(eta,2);
             double noSpin = 1.2922261617161441 + 0.0019318405961363861*eta;
             double eqSpin = (0.04927982551108649 - 0.6703778360948937*eta + 2.6625014134659772*eta2)*S;
-            double uneqSpin = 1.2001101665670462*(chi1 + pow(chi1,2) - 2.*chi1*chi2 + (-1. + chi2)*chi2)*eta2*delta;
+            double uneqSpin = 1.2001101665670462*(pWF->chi1L + pow(pWF->chi1L,2) - 2.*pWF->chi1L*pWF->chi2L + (-1. + pWF->chi2L)*pWF->chi2L)*eta2*delta;
             total = noSpin + eqSpin + uneqSpin;
             break;
         }
-        default:{XLAL_ERROR_REAL8(XLAL_EINVAL,"Error in IMRPhenomXHM_RD_Amp_21_sigma: version is not valid. Recommended version is 122018.");}
+        case 122022:{
+            double eta = pWF->eta;
+            double S = pWF->STotR;
+            double chidiff = pWF->dchi_half;
+            double eta1 = eta;
+            double eta2 = eta1 * eta1;
+            double eta3 = eta1 * eta2;
+            double S1 = S;
+            double chidiff1 = chidiff;
+            total = fabs(1.374451177213076 - 0.1147381625630186*eta1 + chidiff1*(0.6646459256372743*eta1 - 5.020585319906719*eta2 + 9.817281653770431*eta3) + chidiff1*(3.8734254747587973*eta1 - 39.880716190740465*eta2 + 99.05511583518896*eta3)*S1 + S1*(0.013272603498067647*(1.809972721953344 - 12.560287006325837*eta1 - 134.597005438578*eta2 + 786.2235720637008*eta3) + 0.006850483944311038*(-6.478737679813189 - 200.29813775611166*eta1 + 2744.3629484255357*eta2 - 7612.096007280672*eta3)*S1));
+            break;
+        }
+        default:{XLAL_ERROR_REAL8(XLAL_EINVAL,"Error in IMRPhenomXHM_RD_Amp_21_sigma: version %i is not valid.", RDAmpFlag);}
     }
     return total;
 }
 
-static double IMRPhenomXHM_RD_Amp_33_sigma(UNUSED double eta, UNUSED double S, UNUSED double chi1, UNUSED double chi2, int RDAmpFlag) {
-    UNUSED double total=0;
+static double IMRPhenomXHM_RD_Amp_33_sigma(UNUSED IMRPhenomXWaveformStruct *pWF, int RDAmpFlag) {
+    double total=0;
     switch (RDAmpFlag){
         case 122018:{
             double noSpin = 1.3;
@@ -228,13 +316,13 @@ static double IMRPhenomXHM_RD_Amp_33_sigma(UNUSED double eta, UNUSED double S, U
             total = noSpin + eqSpin + uneqSpin;
             break;
         }
-        default:{XLAL_ERROR_REAL8(XLAL_EINVAL,"Error in IMRPhenomXHM_RD_Amp_33_sigma: version is not valid. Recommended version is 122018.");}
+        default:{XLAL_ERROR_REAL8(XLAL_EINVAL,"Error in IMRPhenomXHM_RD_Amp_33_sigma: version %i is not valid.", RDAmpFlag);}
     }
     return total;
 }
 
-static double IMRPhenomXHM_RD_Amp_32_sigma(UNUSED double eta, UNUSED double S, UNUSED double chi1, UNUSED double chi2, int RDAmpFlag) {
-    UNUSED double total=0;
+static double IMRPhenomXHM_RD_Amp_32_sigma(UNUSED IMRPhenomXWaveformStruct *pWF, int RDAmpFlag) {
+    double total=0;
     switch (RDAmpFlag){
         case 122018:{
             double noSpin = 1.33;
@@ -243,13 +331,29 @@ static double IMRPhenomXHM_RD_Amp_32_sigma(UNUSED double eta, UNUSED double S, U
             total = noSpin + eqSpin + uneqSpin;
             break;
         }
-        default:{XLAL_ERROR_REAL8(XLAL_EINVAL,"Error in IMRPhenomXHM_RD_Amp_32_sigma: version is not valid. Recommended version is 122018.");}
+        case 122022:{
+            double eta = pWF->eta;
+            double delta = pWF->delta;
+            double S = pWF->STotR;
+            double chidiff = pWF->dchi_half;
+            double eta1 = eta;
+            double eta2 = eta1 * eta1;
+            double eta3 = eta1 * eta2;
+            double eta4 = eta1 * eta3;
+            double eta5 = eta1 * eta4;
+            double S1 = S;
+            double chidiff1 = chidiff;
+            double chidiff2 = chidiff1 * chidiff1;
+            total = 1.3353917551819414 + 0.13401718687342024*eta1 + chidiff1*delta*(144.37065005786636*eta3 - 754.4085447486738*eta4 + 123.86194078913776*eta5) + chidiff2*(209.09202210427972*eta3 - 1769.4658099037918*eta4 + 3592.287297392387*eta5) + S1*(-0.012086025709597246*(-6.230497473791485 + 600.5968613752918*eta1 - 6606.1009717965735*eta2 + 17277.60594350428*eta3) - 0.06066548829900489*(-0.9208054306316676 + 142.0346574366267*eta1 - 1567.249168668069*eta2 + 4119.373703246675*eta3)*S1);
+            break;
+        }
+        default:{XLAL_ERROR_REAL8(XLAL_EINVAL,"Error in IMRPhenomXHM_RD_Amp_32_sigma: version %i is not valid.", RDAmpFlag);}
     }
     return total;
 }
 
-static double IMRPhenomXHM_RD_Amp_44_sigma(UNUSED double eta, UNUSED double S, UNUSED double chi1, UNUSED double chi2, int RDAmpFlag) {
-    UNUSED double total=0;
+static double IMRPhenomXHM_RD_Amp_44_sigma(UNUSED IMRPhenomXWaveformStruct *pWF, int RDAmpFlag) {
+    double total=0;
     switch (RDAmpFlag){
         case 122018:{
             double noSpin = 1.33;
@@ -258,60 +362,613 @@ static double IMRPhenomXHM_RD_Amp_44_sigma(UNUSED double eta, UNUSED double S, U
             total = noSpin + eqSpin + uneqSpin;
             break;
         }
-        default:{XLAL_ERROR_REAL8(XLAL_EINVAL,"Error in IMRPhenomXHM_RD_Amp_44_sigma: version is not valid. Recommended version is 122018.");}
+        default:{XLAL_ERROR_REAL8(XLAL_EINVAL,"Error in IMRPhenomXHM_RD_Amp_44_sigma: version %i is not valid.", RDAmpFlag);}
     }
     return total;
 }
 
 
+static double IMRPhenomXHM_RD_Amp_21_rdcp1(IMRPhenomXWaveformStruct *pWF, int RDAmpFlag){
+	double total=0;
+	switch (RDAmpFlag){
+        case 122022:{
+            double eta = pWF->eta;
+            double delta = pWF->delta;
+            double S = pWF->chiPNHat;
+            double chidiff = pWF->dchi_half;
+            double eta1 = eta;
+            double eta2 = eta1 * eta1;
+            double eta3 = eta1 * eta2;
+            double eta4 = eta1 * eta3;
+            double eta5 = eta1 * eta4;
+            double eta6 = eta1 * eta5;
+            double S1 = S;
+            double S2 = S1 * S1;
+            double chidiff1 = chidiff;
+            total = fabs(delta*eta1*(12.880905080761432 - 23.5291063016996*eta1 + 92.6090002736012*eta2 - 175.16681482428694*eta3) + chidiff1*delta*eta1*(26.89427230731867*eta1 - 710.8871223808559*eta2 + 2255.040486907459*eta3) + chidiff1*delta*eta1*(21.402708785047853*eta1 - 232.07306353130417*eta2 + 591.1097623278739*eta3)*S1 + delta*eta1*S1*(-10.090867481062709*(0.9580746052260011 + 5.388149112485179*eta1 - 107.22993216128548*eta2 + 801.3948756800821*eta3 - 2688.211889175019*eta4 + 3950.7894052628735*eta5 - 1992.9074348833092*eta6) - 0.42972412296628143*(1.9193131231064235 + 139.73149069609775*eta1 - 1616.9974609915555*eta2 - 3176.4950303461164*eta3 + 107980.65459735804*eta4 - 479649.75188253267*eta5 + 658866.0983367155*eta6)*S1) + chidiff1*eta5*(-1512.439342647443 + 175.59081294852444*S1 + 10.13490934572329*S2));
+            break;
+        }
+    default:{XLAL_ERROR_REAL8(XLAL_EINVAL,"Error in IMRPhenomXHM_RD_Amp_21_rdcp1: version %i is not valid.", RDAmpFlag);}
+  }
+  return total;
+}
+
+static double IMRPhenomXHM_RD_Amp_21_rdcp2(IMRPhenomXWaveformStruct *pWF, int RDAmpFlag){
+	double total=0;
+	switch (RDAmpFlag){
+        case 122022:{
+            double eta = pWF->eta;
+            double delta = pWF->delta;
+            double S = pWF->chiPNHat;
+            double chidiff = pWF->dchi_half;
+            double eta1 = eta;
+            double eta2 = eta1 * eta1;
+            double eta3 = eta1 * eta2;
+            double eta4 = eta1 * eta3;
+            double eta5 = eta1 * eta4;
+            double S1 = S;
+            double S2 = S1 * S1;
+            double chidiff1 = chidiff;
+            total = fabs(delta*(9.112452928978168 - 7.5304766811877455*eta1)*eta1 + chidiff1*delta*eta1*(16.236533863306132*eta1 - 500.11964987628926*eta2 + 1618.0818430353293*eta3) + chidiff1*delta*eta1*(2.7866868976718226*eta1 - 0.4210629980868266*eta2 - 20.274691328125606*eta3)*S1 + chidiff1*eta5*(-1116.4039232324135 + 245.73200219767514*S1 + 21.159179960295855*S2) + delta*eta1*S1*(-8.236485576091717*(0.8917610178208336 + 5.1501231412520285*eta1 - 87.05136337926156*eta2 + 519.0146702141192*eta3 - 997.6961311502365*eta4) + 0.2836840678615208*(-0.19281297100324718 - 57.65586769647737*eta1 + 586.7942442434971*eta2 - 1882.2040277496196*eta3 + 2330.3534917059906*eta4)*S1 + 0.40226131643223145*(-3.834742668014861 + 190.42214703482531*eta1 - 2885.5110686004946*eta2 + 16087.433824017446*eta3 - 29331.524552164105*eta4)*S2));
+            break;
+        }
+    default:{XLAL_ERROR_REAL8(XLAL_EINVAL,"Error in IMRPhenomXHM_RD_Amp_21_rdcp2: version %i is not valid.", RDAmpFlag);}
+  }
+  return total;
+}
+
+static double IMRPhenomXHM_RD_Amp_21_rdcp3(IMRPhenomXWaveformStruct *pWF, int RDAmpFlag){
+	double total=0;
+	switch (RDAmpFlag){
+        case 122022:{
+            double eta = pWF->eta;
+            double delta = pWF->delta;
+            double S = pWF->chiPNHat;
+            double chidiff = pWF->dchi_half;
+            double eta1 = eta;
+            double eta2 = eta1 * eta1;
+            double eta3 = eta1 * eta2;
+            double eta4 = eta1 * eta3;
+            double eta5 = eta1 * eta4;
+            double S1 = S;
+            double S2 = S1 * S1;
+            double chidiff1 = chidiff;
+            total = fabs(delta*(2.920930733198033 - 3.038523690239521*eta1)*eta1 + chidiff1*delta*eta1*(6.3472251472354975*eta1 - 171.23657247338042*eta2 + 544.1978232314333*eta3) + chidiff1*delta*eta1*(1.9701247529688362*eta1 - 2.8616711550845575*eta2 - 0.7347258030219584*eta3)*S1 + chidiff1*eta5*(-334.0969956136684 + 92.91301644484749*S1 - 5.353399481074393*S2) + delta*eta1*S1*(-2.7294297839371824*(1.148166706456899 - 4.384077347340523*eta1 + 36.120093043420326*eta2 - 87.26454353763077*eta3) + 0.23949142867803436*(-0.6931516433988293 + 33.33372867559165*eta1 - 307.3404155231787*eta2 + 862.3123076782916*eta3)*S1 + 0.1930861073906724*(3.7735099269174106 - 19.11543562444476*eta1 - 78.07256429516346*eta2 + 485.67801863289293*eta3)*S2));
+            break;
+        }
+    default:{XLAL_ERROR_REAL8(XLAL_EINVAL,"Error in IMRPhenomXHM_RD_Amp_21_rdcp3: version %i is not valid.", RDAmpFlag);}
+  }
+  return total;
+}
+
+static double IMRPhenomXHM_RD_Amp_33_rdcp1(IMRPhenomXWaveformStruct *pWF, int RDAmpFlag){
+	double total=0;
+	switch (RDAmpFlag){
+        case 122022:{
+            double eta = pWF->eta;
+            double delta = pWF->delta;
+            double S = pWF->STotR;
+            double chidiff = pWF->dchi_half;
+            double eta1 = eta;
+            double eta2 = eta1 * eta1;
+            double eta3 = eta1 * eta2;
+            double eta4 = eta1 * eta3;
+            double eta5 = eta1 * eta4;
+            double S1 = S;
+            double S2 = S1 * S1;
+            double chidiff1 = chidiff;
+            double chidiff2 = chidiff1 * chidiff1;
+            total = delta*eta1*(12.439702602599235 - 4.436329538596615*eta1 + 22.780673360839497*eta2) + delta*eta1*(chidiff1*(-41.04442169938298*eta1 + 502.9246970179746*eta2 - 1524.2981907688634*eta3) + chidiff2*(32.23960072974939*eta1 - 365.1526474476759*eta2 + 1020.6734178547847*eta3)) + chidiff1*delta*eta1*(-52.85961155799673*eta1 + 577.6347407795782*eta2 - 1653.496174539196*eta3)*S1 + chidiff1*eta5*(257.33227387984863 - 34.5074027042393*chidiff2 - 21.836905132600755*S1 - 15.81624534976308*S2) + 13.499999999999998*delta*eta1*S1*(-0.13654149379906394*(2.719687834084113 + 29.023992126142304*eta1 - 742.1357702210267*eta2 + 4142.974510926698*eta3 - 6167.08766058184*eta4 - 3591.1757995710486*eta5) - 0.06248535354306988*(6.697567446351289 - 78.23231700361792*eta1 + 444.79350113344543*eta2 - 1907.008984765889*eta3 + 6601.918552659412*eta4 - 10056.98422430965*eta5)*S1)*pow(-3.9329308614837704 + S1,-1);
+            break;
+        }
+    default:{XLAL_ERROR_REAL8(XLAL_EINVAL,"Error in IMRPhenomXHM_RD_Amp_33_rdcp1: version %i is not valid.", RDAmpFlag);}
+  }
+  return total;
+}
+
+static double IMRPhenomXHM_RD_Amp_33_rdcp2(IMRPhenomXWaveformStruct *pWF, int RDAmpFlag){
+	double total=0;
+	switch (RDAmpFlag){
+        case 122022:{
+            double eta = pWF->eta;
+            double delta = pWF->delta;
+            double S = pWF->STotR;
+            double chidiff = pWF->dchi_half;
+            double eta1 = eta;
+            double eta2 = eta1 * eta1;
+            double eta3 = eta1 * eta2;
+            double eta4 = eta1 * eta3;
+            double eta5 = eta1 * eta4;
+            double S1 = S;
+            double S2 = S1 * S1;
+            double chidiff1 = chidiff;
+            double chidiff2 = chidiff1 * chidiff1;
+            total = delta*eta1*(8.425057692276933 + 4.543696144846763*eta1) + chidiff1*delta*eta1*(-32.18860840414171*eta1 + 412.07321398189293*eta2 - 1293.422289802462*eta3) + chidiff1*delta*eta1*(-17.18006888428382*eta1 + 190.73514518113845*eta2 - 636.4802385540647*eta3)*S1 + delta*eta1*S1*(0.1206817303851239*(8.667503604073314 - 144.08062755162752*eta1 + 3188.189172446398*eta2 - 35378.156133055556*eta3 + 163644.2192178668*eta4 - 265581.70142471837*eta5) + 0.08028332044013944*(12.632478544060636 - 322.95832000179297*eta1 + 4777.45310151897*eta2 - 35625.58409457366*eta3 + 121293.97832549023*eta4 - 148782.33687815256*eta5)*S1) + chidiff1*eta5*(159.72371180117415 - 29.10412708633528*chidiff2 - 1.873799747678187*S1 + 41.321480132899524*S2);
+            break;
+        }
+    default:{XLAL_ERROR_REAL8(XLAL_EINVAL,"Error in IMRPhenomXHM_RD_Amp_33_rdcp2: version %i is not valid.", RDAmpFlag);}
+  }
+  return total;
+}
+
+static double IMRPhenomXHM_RD_Amp_33_rdcp3(IMRPhenomXWaveformStruct *pWF, int RDAmpFlag){
+	double total=0;
+	switch (RDAmpFlag){
+        case 122022:{
+            double eta = pWF->eta;
+            double delta = pWF->delta;
+            double S = pWF->STotR;
+            double chidiff = pWF->dchi_half;
+            double eta1 = eta;
+            double eta2 = eta1 * eta1;
+            double eta3 = eta1 * eta2;
+            double eta4 = eta1 * eta3;
+            double eta5 = eta1 * eta4;
+            double S1 = S;
+            double S2 = S1 * S1;
+            double chidiff1 = chidiff;
+            double chidiff2 = chidiff1 * chidiff1;
+            total = delta*eta1*(2.485784720088995 + 2.321696430921996*eta1) + delta*eta1*(chidiff1*(-10.454376404653859*eta1 + 147.10344302665484*eta2 - 496.1564538739011*eta3) + chidiff2*(-5.9236399792925996*eta1 + 65.86115501723127*eta2 - 197.51205149250532*eta3)) + chidiff1*delta*eta1*(-10.27418232676514*eta1 + 136.5150165348149*eta2 - 473.30988537734174*eta3)*S1 + chidiff1*eta5*(32.07819766300362 - 3.071422453072518*chidiff2 + 35.09131921815571*S1 + 67.23189816732847*S2) + 13.499999999999998*delta*eta1*S1*(0.0011484326782460882*(4.1815722950796035 - 172.58816646768219*eta1 + 5709.239330076732*eta2 - 67368.27397765424*eta3 + 316864.0589150127*eta4 - 517034.11171277676*eta5) - 0.009496797093329243*(0.9233282181397624 - 118.35865186626413*eta1 + 2628.6024206791726*eta2 - 23464.64953722729*eta3 + 94309.57566199072*eta4 - 140089.40725211444*eta5)*S1)*pow(0.09549360183532198 - 0.41099904730526465*S1 + S2,-1);
+            break;
+        }
+    default:{XLAL_ERROR_REAL8(XLAL_EINVAL,"Error in IMRPhenomXHM_RD_Amp_33_rdcp3: version %i is not valid.", RDAmpFlag);}
+  }
+  return total;
+}
+
+static double IMRPhenomXHM_RD_Amp_44_rdcp1(IMRPhenomXWaveformStruct *pWF, int RDAmpFlag){
+	double total=0;
+	switch (RDAmpFlag){
+        case 122022:{
+            double eta = pWF->eta;
+            double delta = pWF->delta;
+            double S = pWF->STotR;
+            double chidiff = pWF->dchi_half;
+            double eta1 = eta;
+            double eta2 = eta1 * eta1;
+            double eta3 = eta1 * eta2;
+            double eta4 = eta1 * eta3;
+            double eta5 = eta1 * eta4;
+            double eta6 = eta1 * eta5;
+            double S1 = S;
+            double S2 = S1 * S1;
+            double chidiff1 = chidiff;
+            double chidiff2 = chidiff1 * chidiff1;
+            total = eta1*(chidiff1*delta*(-8.51952446214978*eta1 + 117.76530248141987*eta2 - 297.2592736781142*eta3) + chidiff2*(-0.2750098647982238*eta1 + 4.456900599347149*eta2 - 8.017569928870929*eta3)) + eta1*(5.635069974807398 - 33.67252878543393*eta1 + 287.9418482197136*eta2 - 3514.3385364216438*eta3 + 25108.811524802128*eta4 - 98374.18361532023*eta5 + 158292.58792484726*eta6) + eta1*S1*(-0.4360849737360132*(-0.9543114627170375 - 58.70494649755802*eta1 + 1729.1839588870455*eta2 - 16718.425586396803*eta3 + 71236.86532610047*eta4 - 111910.71267453219*eta5) - 0.024861802943501172*(-52.25045490410733 + 1585.462602954658*eta1 - 15866.093368857853*eta2 + 35332.328181283*eta3 + 168937.32229060197*eta4 - 581776.5303770923*eta5)*S1 + 0.005856387555754387*(186.39698091707513 - 9560.410655118145*eta1 + 156431.3764198244*eta2 - 1.0461268207440731e6*eta3 + 3.054333578686424e6*eta4 - 3.2369858387064277e6*eta5)*S2);
+            break;
+        }
+    default:{XLAL_ERROR_REAL8(XLAL_EINVAL,"Error in IMRPhenomXHM_RD_Amp_44_rdcp1: version %i is not valid.", RDAmpFlag);}
+  }
+  return total;
+}
+
+static double IMRPhenomXHM_RD_Amp_44_rdcp2(IMRPhenomXWaveformStruct *pWF, int RDAmpFlag){
+	double total=0;
+	switch (RDAmpFlag){
+        case 122022:{
+            double eta = pWF->eta;
+            double delta = pWF->delta;
+            double S = pWF->STotR;
+            double chidiff = pWF->dchi_half;
+            double eta1 = eta;
+            double eta2 = eta1 * eta1;
+            double eta3 = eta1 * eta2;
+            double eta4 = eta1 * eta3;
+            double eta5 = eta1 * eta4;
+            double S1 = S;
+            double S2 = S1 * S1;
+            double chidiff1 = chidiff;
+            double chidiff2 = chidiff1 * chidiff1;
+            total = eta1*(chidiff1*delta*(-2.861653255976984*eta1 + 50.50227103211222*eta2 - 123.94152825700999*eta3) + chidiff2*(2.9415751419018865*eta1 - 28.79779545444817*eta2 + 72.40230240887851*eta3)) + eta1*(3.2461722686239307 + 25.15310593958783*eta1 - 792.0167314124681*eta2 + 7168.843978909433*eta3 - 30595.4993786313*eta4 + 49148.57065911245*eta5) + eta1*S1*(-0.23311779185707152*(-1.0795711755430002 - 20.12558747513885*eta1 + 1163.9107546486134*eta2 - 14672.23221502075*eta3 + 73397.72190288734*eta4 - 127148.27131388368*eta5) + 0.025805905356653*(11.929946153728276 + 350.93274421955806*eta1 - 14580.02701600596*eta2 + 174164.91607515427*eta3 - 819148.9390278616*eta4 + 1.3238624538095295e6*eta5)*S1 + 0.019740635678180102*(-7.046295936301379 + 1535.781942095697*eta1 - 27212.67022616794*eta2 + 201981.0743810629*eta3 - 696891.1349708183*eta4 + 910729.0219043035*eta5)*S2);
+            break;
+        }
+    default:{XLAL_ERROR_REAL8(XLAL_EINVAL,"Error in IMRPhenomXHM_RD_Amp_44_rdcp2: version %i is not valid.", RDAmpFlag);}
+  }
+  return total;
+}
+
+static double IMRPhenomXHM_RD_Amp_44_rdcp3(IMRPhenomXWaveformStruct *pWF, int RDAmpFlag){
+	double total=0;
+	switch (RDAmpFlag){
+        case 122022:{
+            double eta = pWF->eta;
+            double delta = pWF->delta;
+            double S = pWF->STotR;
+            double chidiff = pWF->dchi_half;
+            double eta1 = eta;
+            double eta2 = eta1 * eta1;
+            double eta3 = eta1 * eta2;
+            double eta4 = eta1 * eta3;
+            double eta5 = eta1 * eta4;
+            double S1 = S;
+            double chidiff1 = chidiff;
+            double chidiff2 = chidiff1 * chidiff1;
+            total = eta1*(chidiff1*delta*(2.4286414692113816*eta1 - 23.213332913737403*eta2 + 66.58241012629095*eta3) + chidiff2*(3.085167288859442*eta1 - 31.60440418701438*eta2 + 78.49621016381445*eta3)) + eta1*(0.861883217178703 + 13.695204704208976*eta1 - 337.70598252897696*eta2 + 2932.3415281149432*eta3 - 12028.786386004691*eta4 + 18536.937955014455*eta5) + eta1*S1*(-0.048465588779596405*(-0.34041762314288154 - 81.33156665674845*eta1 + 1744.329802302927*eta2 - 16522.343895064576*eta3 + 76620.18243090731*eta4 - 133340.93723954144*eta5) + 0.024804027856323612*(-8.666095805675418 + 711.8727878341302*eta1 - 13644.988225595187*eta2 + 112832.04975245205*eta3 - 422282.0368440555*eta4 + 584744.0406581408*eta5)*S1);
+            break;
+        }
+    default:{XLAL_ERROR_REAL8(XLAL_EINVAL,"Error in IMRPhenomXHM_RD_Amp_44_rdcp3: version %i is not valid.", RDAmpFlag);}
+  }
+  return total;
+}
+
+static double IMRPhenomXHM_RD_Amp_32_rdaux1(IMRPhenomXWaveformStruct *pWF, int RDAmpFlag){
+	double total=0;
+	switch (RDAmpFlag){
+        case 122022:{
+            double eta = pWF->eta;
+            double delta = pWF->delta;
+            double S = pWF->STotR;
+            double chidiff = pWF->dchi_half;
+            double eta1 = eta;
+            double eta2 = eta1 * eta1;
+            double eta3 = eta1 * eta2;
+            double eta4 = eta1 * eta3;
+            double eta5 = eta1 * eta4;
+            double eta6 = eta1 * eta5;
+            double S1 = S;
+            double chidiff1 = chidiff;
+            double chidiff2 = chidiff1 * chidiff1;
+            total = chidiff2*(-4.188795724777721*eta2 + 53.39200466700963*eta3 - 131.19660856923554*eta4) + chidiff1*delta*(14.284921364132623*eta2 - 321.26423637658746*eta3 + 1242.865584938088*eta4) + S1*(-0.022968727462555794*(83.66854837403105*eta1 - 3330.6261333413177*eta2 + 77424.12614733395*eta3 - 710313.3016672594*eta4 + 2.6934917075009225e6*eta5 - 3.572465179268999e6*eta6) + 0.0014795114305436387*(-1672.7273629876313*eta1 + 90877.38260964208*eta2 - 1.6690169155105734e6*eta3 + 1.3705532554135624e7*eta4 - 5.116110998398143e7*eta5 + 7.06066766311127e7*eta6)*S1) + (4.45156488896258*eta1 - 77.39303992494544*eta2 + 522.5070635563092*eta3 - 1642.3057499049708*eta4 + 2048.333892310575*eta5)*pow(1 - 9.611489164758915*eta1 + 24.249594730050312*eta2,-1);
+            break;
+        }
+    default:{XLAL_ERROR_REAL8(XLAL_EINVAL,"Error in IMRPhenomXHM_RD_Amp_32_rdaux1: version %i is not valid.", RDAmpFlag);}
+  }
+  return total;
+}
+
+static double IMRPhenomXHM_RD_Amp_32_rdaux2(IMRPhenomXWaveformStruct *pWF, int RDAmpFlag){
+	double total=0;
+	switch (RDAmpFlag){
+        case 122022:{
+            double eta = pWF->eta;
+            double delta = pWF->delta;
+            double S = pWF->chiPNHat;
+            double chidiff = pWF->dchi_half;
+            double eta1 = eta;
+            double eta2 = eta1 * eta1;
+            double eta3 = eta1 * eta2;
+            double eta4 = eta1 * eta3;
+            double eta5 = eta1 * eta4;
+            double eta6 = eta1 * eta5;
+            double eta7 = eta1 * eta6;
+            double S1 = S;
+            double chidiff1 = chidiff;
+            double chidiff2 = chidiff1 * chidiff1;
+            total = chidiff2*(-18.550171209458394*eta2 + 188.99161055445936*eta3 - 440.26516625611*eta4) + chidiff1*delta*(13.132625215315063*eta2 - 340.5204040505528*eta3 + 1327.1224176812448*eta4) + S1*(-0.16707403272774676*(6.678916447469937*eta1 + 1331.480396625797*eta2 - 41908.45179140144*eta3 + 520786.0225074669*eta4 - 3.1894624909922685e6*eta5 + 9.51553823212259e6*eta6 - 1.1006903622406831e7*eta7) + 0.015205286051218441*(108.10032279461095*eta1 - 16084.215590200103*eta2 + 462957.5593513407*eta3 - 5.635028227588545e6*eta4 + 3.379925277713386e7*eta5 - 9.865815275452062e7*eta6 + 1.1201307979786257e8*eta7)*S1) + (3.902154247490771*eta1 - 55.77521071924907*eta2 + 294.9496843041973*eta3 - 693.6803787318279*eta4 + 636.0141528226893*eta5)*pow(1 - 8.56699762573719*eta1 + 19.119341007236955*eta2,-1);
+            break;
+        }
+    default:{XLAL_ERROR_REAL8(XLAL_EINVAL,"Error in IMRPhenomXHM_RD_Amp_32_rdaux2: version %i is not valid.", RDAmpFlag);}
+  }
+  return total;
+}
+
+static double IMRPhenomXHM_RD_Amp_32_rdcp1(IMRPhenomXWaveformStruct *pWF, int RDAmpFlag){
+	double total=0;
+	switch (RDAmpFlag){
+        case 122022:{
+            double eta = pWF->eta;
+            double delta = pWF->delta;
+            double S = pWF->STotR;
+            double chidiff = pWF->dchi_half;
+            double eta1 = eta;
+            double eta2 = eta1 * eta1;
+            double eta3 = eta1 * eta2;
+            double eta4 = eta1 * eta3;
+            double eta5 = eta1 * eta4;
+            double eta6 = eta1 * eta5;
+            double S1 = S;
+            double S2 = S1 * S1;
+            double chidiff1 = chidiff;
+            double chidiff2 = chidiff1 * chidiff1;
+            total = chidiff2*(-261.63903838092017*eta3 + 2482.4929818200458*eta4 - 5662.765952006266*eta5) + chidiff1*delta*(200.3023530582654*eta3 - 3383.07742098347*eta4 + 11417.842708417566*eta5) + chidiff2*(-177.2481070662751*eta3 + 1820.8637746828358*eta4 - 4448.151940319403*eta5)*S1 + chidiff1*delta*(412.749304734278*eta3 - 4156.641392955615*eta4 + 10116.974216563232*eta5)*S1 + S1*(-0.07383539239633188*(40.59996146686051*eta1 - 527.5322650311067*eta2 + 4167.108061823492*eta3 - 13288.883172763119*eta4 - 23800.671572828596*eta5 + 146181.8016013141*eta6) + 0.03576631753501686*(-13.96758180764024*eta1 - 797.1235306450683*eta2 + 18007.56663810595*eta3 - 151803.40642097822*eta4 + 593811.4596071478*eta5 - 878123.747877138*eta6)*S1 + 0.01007493097350273*(-27.77590078264459*eta1 + 4011.1960424049857*eta2 - 152384.01804465035*eta3 + 1.7595145936445233e6*eta4 - 7.889230647117076e6*eta5 + 1.2172078072446395e7*eta6)*S2) + (4.146029818148087*eta1 - 61.060972560568054*eta2 + 336.3725848841942*eta3 - 832.785332776221*eta4 + 802.5027431944313*eta5)*pow(1 - 8.662174796705683*eta1 + 19.288918757536685*eta2,-1);
+            break;
+        }
+    default:{XLAL_ERROR_REAL8(XLAL_EINVAL,"Error in IMRPhenomXHM_RD_Amp_32_rdcp1: version is not valid. Recommended version is 122022.");}
+  }
+  return total;
+}
+
+static double IMRPhenomXHM_RD_Amp_32_rdcp2(IMRPhenomXWaveformStruct *pWF, int RDAmpFlag){
+	double total=0;
+	switch (RDAmpFlag){
+        case 122022:{
+            double eta = pWF->eta;
+            double delta = pWF->delta;
+            double S = pWF->STotR;
+            double chidiff = pWF->dchi_half;
+            double eta1 = eta;
+            double eta2 = eta1 * eta1;
+            double eta3 = eta1 * eta2;
+            double eta4 = eta1 * eta3;
+            double eta5 = eta1 * eta4;
+            double eta6 = eta1 * eta5;
+            double S1 = S;
+            double S2 = S1 * S1;
+            double chidiff1 = chidiff;
+            double chidiff2 = chidiff1 * chidiff1;
+            total = chidiff2*(-220.42133216774002*eta3 + 2082.031407555522*eta4 - 4739.292554291661*eta5) + chidiff1*delta*(179.07548162694007*eta3 - 2878.2078963030094*eta4 + 9497.998559135678*eta5) + chidiff2*(-128.07917402087625*eta3 + 1392.4598433465628*eta4 - 3546.2644951338134*eta5)*S1 + chidiff1*delta*(384.31792882093424*eta3 - 3816.5687272960417*eta4 + 9235.479593415908*eta5)*S1 + S1*(-0.06144774696295017*(35.72693522898656*eta1 - 168.08433700852038*eta2 - 3010.678442066521*eta3 + 45110.034521934074*eta4 - 231569.4154711447*eta5 + 414234.84895584086*eta6) + 0.03663881822701642*(-22.057692852225696*eta1 + 223.9912685075838*eta2 - 1028.5261783449762*eta3 - 12761.957255385*eta4 + 141784.13567610556*eta5 - 328718.5349981628*eta6)*S1 + 0.004849853669413881*(-90.35491669965123*eta1 + 19286.158446325957*eta2 - 528138.5557827373*eta3 + 5.175061086459432e6*eta4 - 2.1142182400264673e7*eta5 + 3.0737963347449116e7*eta6)*S2) + (3.133378729082171*eta1 - 45.83572706555282*eta2 + 250.23275606463622*eta3 - 612.0498767005383*eta4 + 580.3574091493459*eta5)*pow(1 - 8.698032720488515*eta1 + 19.38621948411302*eta2,-1);
+            break;
+        }
+    default:{XLAL_ERROR_REAL8(XLAL_EINVAL,"Error in IMRPhenomXHM_RD_Amp_32_rdcp2: version is not valid. Recommended version is 122022.");}
+  }
+  return total;
+}
+
+static double IMRPhenomXHM_RD_Amp_32_rdcp3(IMRPhenomXWaveformStruct *pWF, int RDAmpFlag){
+	double total=0;
+	switch (RDAmpFlag){
+        case 122022:{
+            double eta = pWF->eta;
+            double delta = pWF->delta;
+            double S = pWF->STotR;
+            double chidiff = pWF->dchi_half;
+            double eta1 = eta;
+            double eta2 = eta1 * eta1;
+            double eta3 = eta1 * eta2;
+            double eta4 = eta1 * eta3;
+            double eta5 = eta1 * eta4;
+            double eta6 = eta1 * eta5;
+            double S1 = S;
+            double chidiff1 = chidiff;
+            double chidiff2 = chidiff1 * chidiff1;
+            total = chidiff2*(-79.14146757219045*eta3 + 748.8207876524461*eta4 - 1712.3401586150026*eta5) + chidiff1*delta*(65.1786095079065*eta3 - 996.4553252426255*eta4 + 3206.5675278160684*eta5) + chidiff2*(-36.474455088940225*eta3 + 421.8842792746865*eta4 - 1117.0227933265749*eta5)*S1 + chidiff1*delta*(169.07368933925878*eta3 - 1675.2562326502878*eta4 + 4040.0077967763787*eta5)*S1 + S1*(-0.01992370601225598*(36.307098892574196*eta1 - 846.997262853445*eta2 + 16033.60939445582*eta3 - 138800.53021166887*eta4 + 507922.88946543116*eta5 - 647376.1499824544*eta6) + 0.014207919520826501*(-33.80287899746716*eta1 + 1662.2913368534057*eta2 - 31688.885017467597*eta3 + 242813.43893659746*eta4 - 793178.4767168422*eta5 + 929016.897093022*eta6)*S1) + (0.9641853854287679*eta1 - 13.801372413989519*eta2 + 72.80610853168994*eta3 - 168.65551450831953*eta4 + 147.2372582604103*eta5)*pow(1 - 8.65963828355163*eta1 + 19.112920222001367*eta2,-1);
+            break;
+        }
+    default:{XLAL_ERROR_REAL8(XLAL_EINVAL,"Error in IMRPhenomXHM_RD_Amp_32_rdcp3: version is not valid. Recommended version is 122022.");}
+  }
+  return total;
+}
+
+/* End of Amp Parameter Space Fits */
+
+
+/************** Ringdown coefficients from collocation points *************/
+
+static void IMRPhenomXHM_RD_Amp_Coefficients(IMRPhenomXWaveformStruct *pWF22, IMRPhenomXHMWaveformStruct *pWFHM, IMRPhenomXHMAmpCoefficients *pAmp){
+    switch (pWFHM->IMRPhenomXHMRingdownAmpVersion){
+        case 0:{
+            // We have three "fitted" coefficients across parameter space: alambda, lambda and sigma. Sigma will be constat for all the modes except the 21.
+            pAmp->RDCoefficient[0] = fabs(pAmp->RingdownAmpFits[pWFHM->modeInt*3](pWF22,pWFHM->IMRPhenomXHMRingdownAmpFitsVersion));
+            pAmp->RDCoefficient[1] = pAmp->RingdownAmpFits[pWFHM->modeInt*3+1](pWF22,pWFHM->IMRPhenomXHMRingdownAmpFitsVersion);
+            pAmp->RDCoefficient[2] = pAmp->RingdownAmpFits[pWFHM->modeInt*3+2](pWF22,pWFHM->IMRPhenomXHMRingdownAmpFitsVersion);
+            pAmp->RDCoefficient[3] = 1./12.;
+            break;
+        }
+        case 1:
+        case 2:{
+            if (pWFHM->IMRPhenomXHMRingdownAmpVersion == 1){
+                pAmp->RDCoefficient[0] = fabs(pAmp->RingdownAmpFits[pWFHM->modeInt*3](pWF22,pWFHM->IMRPhenomXHMRingdownAmpFitsVersion));
+                pAmp->RDCoefficient[1] = pAmp->RingdownAmpFits[pWFHM->modeInt*3+1](pWF22,pWFHM->IMRPhenomXHMRingdownAmpFitsVersion);
+                pAmp->RDCoefficient[2] = pAmp->RingdownAmpFits[pWFHM->modeInt*3+2](pWF22,pWFHM->IMRPhenomXHMRingdownAmpFitsVersion);
+            }
+            else if (pWFHM->IMRPhenomXHMRingdownAmpVersion == 2){
+                double rdcp1 = fabs(pAmp->RingdownAmpFits[12 + pWFHM->modeInt * 3](pWF22, pWFHM->IMRPhenomXHMRingdownAmpFitsVersion));
+                double rdcp2 = fabs(pAmp->RingdownAmpFits[13 + pWFHM->modeInt * 3](pWF22, pWFHM->IMRPhenomXHMRingdownAmpFitsVersion));
+                double rdcp3 = fabs(pAmp->RingdownAmpFits[14 + pWFHM->modeInt * 3](pWF22, pWFHM->IMRPhenomXHMRingdownAmpFitsVersion));
+
+                pAmp->CollocationPointsFreqsAmplitudeRD[0] = pWFHM->fRING - pWFHM->fDAMP;
+                pAmp->CollocationPointsFreqsAmplitudeRD[1] = pWFHM->fRING;
+                pAmp->CollocationPointsFreqsAmplitudeRD[2] = pWFHM->fRING + pWFHM->fDAMP;
+                /* Apply vetos to RDCP. Assuming they are strain */
+                // float rdveto = 0.01; // Applied over the strain / RescaleFactor_lm
+                // IMRPhenomX_UsefulPowers powers_of_RDCP1, powers_of_RDCP2, powers_of_RDCP3; // PN power v^{1/3} = (2pif/m)
+                // IMRPhenomX_Initialize_Powers(&powers_of_RDCP1, pAmp->CollocationPointsFreqsAmplitudeRD[0]);
+                // IMRPhenomX_Initialize_Powers(&powers_of_RDCP2, pAmp->CollocationPointsFreqsAmplitudeRD[1]);
+                // IMRPhenomX_Initialize_Powers(&powers_of_RDCP3, pAmp->CollocationPointsFreqsAmplitudeRD[2]);
+                // double rescale_factor_lm;
+                // rescale_factor_lm = RescaleFactor(&powers_of_RDCP1, pAmp, 2);
+                // if ( rdcp1 / rescale_factor_lm < rdveto ){
+                //     rdcp1 = 0.9 * rdcp2;
+                // }
+                // rescale_factor_lm = RescaleFactor(&powers_of_RDCP2, pAmp, 2);
+                // if ( rdcp2 / rescale_factor_lm < rdveto ){
+                //     rdcp2 = 0.9 * rdcp1;
+                // }
+                // rescale_factor_lm = RescaleFactor(&powers_of_RDCP3, pAmp, 2);
+                // if ( rdcp3 / rescale_factor_lm < rdveto ){
+                //     rdcp3 = 0.9 * rdcp2;
+                // }
+                if ( rdcp3 >= rdcp2 * rdcp2 / rdcp1 ){
+                    rdcp3 = 0.5 * rdcp2 * rdcp2 / rdcp1;
+                }
+                if ( rdcp3 > rdcp2 ){
+                    rdcp3 = 0.5 * rdcp2;
+                }
+                if (rdcp1 < rdcp2 && rdcp3 > rdcp1){
+                    rdcp3 = rdcp1;
+                }
+                /* End of vetos */
+                pAmp->CollocationPointsValuesAmplitudeRD[0] = rdcp1;
+                pAmp->CollocationPointsValuesAmplitudeRD[1] = rdcp2;
+                pAmp->CollocationPointsValuesAmplitudeRD[2] = rdcp3;
+                REAL8 deno = (sqrt(rdcp1 / rdcp3) - (rdcp1 / rdcp2));
+                if (deno <= 0){
+                    deno = 1e-16;
+                }
+                pAmp->RDCoefficient[0] = rdcp1 * pWFHM->fDAMP / deno;
+                pAmp->RDCoefficient[2] = sqrt(pAmp->RDCoefficient[0] / (rdcp2 * pWFHM->fDAMP));
+                pAmp->RDCoefficient[1] = 0.5 * pAmp->RDCoefficient[2] * log(rdcp1 / rdcp3);
+            }
+                       
+            if (pWFHM->RingdownAmpVeto == 1){
+              pAmp->RDCoefficient[1] = 1;
+              pAmp->RDCoefficient[2] = 1.35;
+              pAmp->RDCoefficient[0] = pAmp->CollocationPointsValuesAmplitudeRD[2] * pWFHM->fDAMP * pAmp->RDCoefficient[2] * pAmp->RDCoefficient[2];
+            }
+            
+            if(pWFHM->fAmpRDfalloff > 0){
+                IMRPhenomX_UsefulPowers powers_of_RDfalloff;
+                IMRPhenomX_Initialize_Powers(&powers_of_RDfalloff, pWFHM->fAmpRDfalloff);
+                REAL8 tmp = pWFHM->fAmpRDfalloff;
+                pWFHM->fAmpRDfalloff = 0;
+                pAmp->RDCoefficient[3] = IMRPhenomXHM_RD_Amp_Ansatz(&powers_of_RDfalloff, pWFHM, pAmp);
+                pAmp->RDCoefficient[4] = -1. * IMRPhenomXHM_RD_Amp_DAnsatz(&powers_of_RDfalloff, pWFHM, pAmp) / pAmp->RDCoefficient[3];
+                pWFHM->fAmpRDfalloff = tmp;
+            }
+            if(pAmp->nCoefficientsRDAux > 0)
+                IMRPhenomXHM_RDAux_Amp_Coefficients(pWF22, pWFHM, pAmp);
+            break;
+        }
+        default:{
+            XLAL_ERROR_VOID(XLAL_EINVAL, "Error in IMRPhenomXHM_RD_Amp_Coefficients: IMRPhenomXHMRingdownAmpVersion is not valid.\n");
+        }
+    }
+}
+
+static void IMRPhenomXHM_RDAux_Amp_Coefficients(IMRPhenomXWaveformStruct *pWF22, IMRPhenomXHMWaveformStruct *pWFHM, IMRPhenomXHMAmpCoefficients *pAmp){
+
+    for(UINT2 i = 0; i < pAmp->nCollocPtsRDAux; i++)
+        pAmp->CollocationPointsValuesAmplitudeRDAux[i] = fabs(pAmp->RingdownAmpFits[24 + i](pWF22, pWFHM->IMRPhenomXHMRingdownAmpFitsVersion));
+    IMRPhenomX_UsefulPowers powers_of_fRDAux;
+    IMRPhenomX_Initialize_Powers(&powers_of_fRDAux, pAmp->fRDAux);
+    pAmp->CollocationPointsValuesAmplitudeRDAux[pAmp->nCollocPtsRDAux] = IMRPhenomXHM_RD_Amp_Ansatz(&powers_of_fRDAux, pWFHM, pAmp); //pAmp->CollocationPointsValuesAmplitudeRD[0];
+    pAmp->CollocationPointsValuesAmplitudeRDAux[pAmp->nCollocPtsRDAux + 1] = IMRPhenomXHM_RD_Amp_DAnsatz(&powers_of_fRDAux, pWFHM, pAmp);
+    if (pWFHM->RingdownAmpVeto == 2 && pAmp->CollocationPointsValuesAmplitudeRDAux[pAmp->nCollocPtsRDAux - 1] < pAmp->CollocationPointsValuesAmplitudeRDAux[pAmp->nCollocPtsRDAux]){
+        pAmp->CollocationPointsValuesAmplitudeRDAux[pAmp->nCollocPtsRDAux - 1] = pAmp->CollocationPointsValuesAmplitudeRDAux[pAmp->nCollocPtsRDAux];
+    }
+    
+    pAmp->CollocationPointsFreqsAmplitudeRDAux[0] = pAmp->fAmpMatchIM;
+    pAmp->CollocationPointsFreqsAmplitudeRDAux[1] = 0.5 * (pAmp->fAmpMatchIM + pAmp->fRDAux); // First Chebyshev node
+    pAmp->CollocationPointsFreqsAmplitudeRDAux[2] = pAmp->fRDAux;
+    pAmp->CollocationPointsFreqsAmplitudeRDAux[3] = pAmp->fRDAux;
+
+
+    /* GSL objects for solving system of equations via LU decomposition */
+    gsl_vector *b, *x;
+    gsl_matrix *A;
+    gsl_permutation *p;
+    int signum; // No need to set, used internally by gsl_linalg_LU_decomp
+
+    p = gsl_permutation_alloc(pAmp->nCoefficientsRDAux);
+    b = gsl_vector_alloc(pAmp->nCoefficientsRDAux);
+    x = gsl_vector_alloc(pAmp->nCoefficientsRDAux);
+    A = gsl_matrix_alloc(pAmp->nCoefficientsRDAux, pAmp->nCoefficientsRDAux);
+
+    /* Define linear system of equations */
+
+    //FIXME: be careful with the indexing, where are the RDaux CollocPoints in CollocationPointsValuesAmplitudeRD?
+    // Should be at the end, although this region goes before than the the "normal RD region".
+    for(INT4 i = 0; i < pAmp->nCoefficientsRDAux; i++){
+      // b is the vector with the values of collocation points
+      gsl_vector_set(b, i, pAmp->CollocationPointsValuesAmplitudeRDAux[i]);
+      //FIXME: distinguish InterAmp ansatzaes versions
+      // Set system matrix: Polynomial at the collocation points frequencies + derivative at the right boundary
+      /* A = (1, f1, f1^2, f1^3, f1^4)
+             (1, f2, f2^2, f2^3, f2^4)
+             (1, f3, f3^2, f3^3, f3^4)
+             (0,  1,   f3, f3^2, f3^3)
+             Until number of collocation points
+      */
+      REAL8 fcollpoint = pAmp->CollocationPointsFreqsAmplitudeRDAux[i];
+      REAL8 fpower = 1.; // 1, f, f^2, f^3, f^4, ...
+      if (i < pAmp->nCoefficientsRDAux - 1){
+          for(INT4 j = 0; j < pAmp->nCoefficientsRDAux; j++){
+              gsl_matrix_set(A, i, j, fpower);
+              fpower *= fcollpoint;
+          }
+      }
+      else{ // Last row of the matrix for the derivative
+          fpower = 1.;
+          gsl_matrix_set(A, i, 0, 0.);
+          for(INT4 j = 1; j < pAmp->nCoefficientsRDAux; j++){
+              gsl_matrix_set(A, i, j, j * fpower);
+              fpower *= fcollpoint;
+          }
+      }
+    }
+
+    /* We now solve the system A x = b via an LU decomposition. x is the solution vector */
+    gsl_linalg_LU_decomp(A, p, &signum);
+    gsl_linalg_LU_solve(A, p, b, x);
+
+    for (INT4 i = 0; i < pAmp->nCoefficientsRDAux; i++){
+        pAmp->RDAuxCoefficient[i] = gsl_vector_get(x, i);
+    }
+
+    gsl_vector_free(b);
+    gsl_vector_free(x);
+    gsl_matrix_free(A);
+    gsl_permutation_free(p);
+}
+
 /************** Amplitude Ringdown Ansatz *************/
 
 // For the modes with mixing this is the ansatz of the spheroidal part.
-static double IMRPhenomXHM_RD_Amp_Ansatz(double ff, IMRPhenomXHMWaveformStruct *pWF, IMRPhenomXHMAmpCoefficients *pAmp){
+static double IMRPhenomXHM_RD_Amp_Ansatz(IMRPhenomX_UsefulPowers *powers_of_Mf, IMRPhenomXHMWaveformStruct *pWFHM, IMRPhenomXHMAmpCoefficients *pAmp){
 
-    int RDAmpFlag = pWF->IMRPhenomXHMRingdownAmpVersion;
-    double frd = pWF->fRING;
-    double fda = pWF->fDAMP;
+    double ff = powers_of_Mf->itself;
+    int RDAmpFlag = pWFHM->IMRPhenomXHMRingdownAmpVersion;
+    double frd = pWFHM->fRING;
+    double fda = pWFHM->fDAMP;
     double dfr = ff - frd;
-    double dfd = fda * pAmp->sigma;
-    double lc  = pAmp->lc;
-    double ampRD;
+    double ampRD = 0.;
 
     switch ( RDAmpFlag )
     {
         case 0: /* Canonical, 3 fitted coefficients + fring, fdamp, lc that are fixed. sigma is also fixed except for the 21 mode. */
+        {   // Only for the 122018 release.
+            double dfd = fda * pAmp->RDCoefficient[2];
+            double lc  = pAmp->RDCoefficient[3];
+            ampRD = (fda *fabs(pAmp->RDCoefficient[0]) * pAmp->RDCoefficient[2])*exp(- dfr * pAmp->RDCoefficient[1] / dfd )/ (dfr*dfr + dfd*dfd)*pow(ff,-lc);
+            // The line below returns the strain amplitude
+            // if (pAmp->RDRescaleFactor == 0){
+            //      ampRD *= (pWFHM->ampNorm * powers_of_Mf->m_seven_sixths);
+            //      //printf("%.10f %.16e\n", ff, ampRD);
+            //  }
+            break;
+        }
+        case 1:
+        case 2:
         {
-            ampRD = (fda *fabs(pAmp->alambda) * pAmp->sigma)*exp(- dfr * pAmp->lambda / dfd )/ (dfr*dfr + dfd*dfd)*pow(ff,-lc);
+            if(pAmp->nCoefficientsRDAux > 0 && !IMRPhenomX_StepFuncBool(ff, pAmp->fRDAux)){
+                 /* Polynomial */
+                double fpower = 1.;
+                for (UINT2 i = 0; i < pAmp->nCoefficientsRDAux; i++){
+                    ampRD += fpower * pAmp->RDAuxCoefficient[i];
+                    fpower *= ff;
+                }
+            }
+            else if (pWFHM->fAmpRDfalloff > 0 && IMRPhenomX_StepFuncBool(ff, pWFHM->fAmpRDfalloff)){
+                ampRD = pAmp->RDCoefficient[3] * exp(- pAmp->RDCoefficient[4] * (ff - pWFHM->fAmpRDfalloff));
+            }
+            else{ /* Lorentzian with exponential falloff */
+                double dfd = fda * pAmp->RDCoefficient[2];
+                ampRD = pAmp->RDCoefficient[0] * fda / ( exp(pAmp->RDCoefficient[1] / dfd * dfr) * (dfr * dfr + dfd * dfd)); // * pWF->ampNorm * factor;
+            }
+            if (pAmp->RDRescaleFactor !=0){
+                ampRD /= RescaleFactor(powers_of_Mf, pAmp, pAmp->RDRescaleFactor);
+            }
             break;
         }
         default:
         {
-            XLAL_ERROR_REAL8(XLAL_EINVAL, "Error in IMRPhenomX_Ringdown_Amp_lm_Ansatz: IMRPhenomXHMRingdownAmpFitsVersion is not valid. Use version 0. \n");
+            XLAL_ERROR_REAL8(XLAL_EINVAL, "Error in IMRPhenomXHM_RD_Amp_Ansatz: IMRPhenomXHMRingdownAmpVersion = %i is not valid. \n", RDAmpFlag);
         }
     }
-
+    
     return ampRD;
 }
 
 
 /*** Derivative of the RD Ansatz for modes without mixing ***/
 
-static double IMRPhenomXHM_RD_Amp_DAnsatz(double ff, IMRPhenomXHMWaveformStruct *pWF, IMRPhenomXHMAmpCoefficients *pAmp){
+static double IMRPhenomXHM_RD_Amp_DAnsatz(IMRPhenomX_UsefulPowers *powers_of_Mf, IMRPhenomXHMWaveformStruct *pWF, IMRPhenomXHMAmpCoefficients *pAmp){
 
+    double ff = powers_of_Mf->itself;
     int RDAmpFlag = pWF->IMRPhenomXHMRingdownAmpVersion;
     double frd = pWF->fRING;
     double fda = pWF->fDAMP;
-    double dfd = fda * pAmp->sigma;
-    double lc  = pAmp->lc;
-    double lambda = pAmp->lambda;
     double DampRD;
-    double numerator,denom,expon;
+    double numerator,denom;
 
     switch ( RDAmpFlag )
     {
         case 0:  /* Canonical, 3 fitted coefficients + fring, fdamp, lc that are fixed. sigma is also fixed except for the 21 mode. */
         {
-            numerator = fabs(pAmp->alambda)*pow(ff,-1.-lc)*( dfd*lc*(frd*frd + dfd*dfd)
+            double dfd = fda * pAmp->RDCoefficient[2];
+            double lc  = pAmp->RDCoefficient[3];
+            double lambda = pAmp->RDCoefficient[1], expon;
+            numerator = fabs(pAmp->RDCoefficient[0])*pow(ff,-1.-lc)*( dfd*lc*(frd*frd + dfd*dfd)
                                                            + ff*( frd*frd*lambda - 2.*dfd*frd*(1.+lc) + dfd*dfd*lambda)
                                                            + ff*ff*( -2.*lambda*frd + dfd*(2.+lc) )
                                                            + ff*ff*ff*( lambda )
@@ -321,9 +978,19 @@ static double IMRPhenomXHM_RD_Amp_DAnsatz(double ff, IMRPhenomXHMWaveformStruct
             DampRD = -numerator*expon/(denom*denom);
             break;
         }
+        case 1:
+        case 2:
+        {
+            double dfr = ff - frd;
+            numerator = pAmp->RDCoefficient[0] * (dfr * dfr * pAmp->RDCoefficient[1] + 2 * fda * dfr * pAmp->RDCoefficient[2] + fda * fda * pAmp->RDCoefficient[1] * pAmp->RDCoefficient[2] * pAmp->RDCoefficient[2]);
+            denom = (dfr * dfr + fda * fda * pAmp->RDCoefficient[2] * pAmp->RDCoefficient[2]);
+            denom = pAmp->RDCoefficient[2] * denom * denom * exp(dfr * pAmp->RDCoefficient[1] / (fda * pAmp->RDCoefficient[2]));
+            DampRD = - numerator / denom;
+            break;
+        }
         default:
         {
-            XLAL_ERROR_REAL8(XLAL_EINVAL, "Error in IMRPhenomX_Ringdown_Amp_lm_Ansatz: IMRPhenomXHMRingdownAmpFitsVersion is not valid. Use version 0. \n");
+            XLAL_ERROR_REAL8(XLAL_EINVAL, "Error in IMRPhenomXHM_RD_Amp_DAnsatz: IMRPhenomXHMRingdownAmpVersion = %i is not valid. \n", RDAmpFlag);
         }
     }
 
@@ -332,8 +999,9 @@ static double IMRPhenomXHM_RD_Amp_DAnsatz(double ff, IMRPhenomXHMWaveformStruct
 
 /*** Derivative of the RD Ansatz for modes with mixing ***/
 // It can not be obtained analytically, so we use finite difference of 4th order
-static double IMRPhenomXHM_RD_Amp_NDAnsatz(double ff, IMRPhenomXHMAmpCoefficients *pAmp,  IMRPhenomXHMPhaseCoefficients *pPhase, IMRPhenomXHMWaveformStruct *pWFHM, IMRPhenomXAmpCoefficients *pAmp22,  IMRPhenomXPhaseCoefficients *pPhase22, IMRPhenomXWaveformStruct *pWF22){
+static double IMRPhenomXHM_RD_Amp_NDAnsatz(IMRPhenomX_UsefulPowers *powers_of_Mf, IMRPhenomXHMAmpCoefficients *pAmp,  IMRPhenomXHMPhaseCoefficients *pPhase, IMRPhenomXHMWaveformStruct *pWFHM, IMRPhenomXAmpCoefficients *pAmp22,  IMRPhenomXPhaseCoefficients *pPhase22, IMRPhenomXWaveformStruct *pWF22){
 
+    double ff = powers_of_Mf->itself;
     double df = 10e-10;
     double Nder;
     double fun2R = ff + 2*df;
@@ -343,16 +1011,16 @@ static double IMRPhenomXHM_RD_Amp_NDAnsatz(double ff, IMRPhenomXHMAmpCoefficient
     IMRPhenomX_UsefulPowers powers_of_fun;
 
     IMRPhenomX_Initialize_Powers(&powers_of_fun,fun2R);
-    fun2R = cabs(SpheroidalToSpherical(fun2R, &powers_of_fun, pAmp22, pPhase22, pAmp, pPhase, pWFHM, pWF22));
+    fun2R = cabs(SpheroidalToSpherical(&powers_of_fun, pAmp22, pPhase22, pAmp, pPhase, pWFHM, pWF22));
 
     IMRPhenomX_Initialize_Powers(&powers_of_fun,funR);
-    funR  = cabs(SpheroidalToSpherical(funR, &powers_of_fun, pAmp22, pPhase22, pAmp, pPhase, pWFHM, pWF22));
+    funR  = cabs(SpheroidalToSpherical(&powers_of_fun, pAmp22, pPhase22, pAmp, pPhase, pWFHM, pWF22));
 
     IMRPhenomX_Initialize_Powers(&powers_of_fun,funL);
-    funL  = cabs(SpheroidalToSpherical(funL, &powers_of_fun, pAmp22, pPhase22, pAmp, pPhase, pWFHM, pWF22));
+    funL  = cabs(SpheroidalToSpherical(&powers_of_fun, pAmp22, pPhase22, pAmp, pPhase, pWFHM, pWF22));
 
     IMRPhenomX_Initialize_Powers(&powers_of_fun,fun2L);
-    fun2L = cabs(SpheroidalToSpherical(fun2L, &powers_of_fun, pAmp22, pPhase22, pAmp, pPhase, pWFHM, pWF22));
+    fun2L = cabs(SpheroidalToSpherical(&powers_of_fun, pAmp22, pPhase22, pAmp, pPhase, pWFHM, pWF22));
 
     Nder = (-fun2R + 8*funR - 8*funL + fun2L )/(12*df);
 
@@ -395,150 +1063,325 @@ void IMRPhenomXHM_Ringdown_Amplitude_Veto(double *V2, double *V3, double V4, IMR
 
 // The spin parameter S = (m1^2*chi1 + m2^2*chi2)/(m1^2 + m2^2)
 
-static double IMRPhenomXHM_RD_Phase_22_alpha2(double eta, double S, double chi1, double chi2, int RDPhaseFlag) {
-    double total=0,eta2,eta3,eta4,delta=sqrt(1-4*eta);
+/* Start of Phase Parameter Space Fits */
+
+static double IMRPhenomXHM_RD_Phase_22_alpha2(IMRPhenomXWaveformStruct *pWF, int RDPhaseFlag) {
+    double total=0;
     switch (RDPhaseFlag){
         case 122019:{
+            double eta = pWF->eta;
+            double S = pWF->STotR;
+            double eta2,eta3,eta4,delta=sqrt(1-4*eta);
             eta2 = pow(eta,2);
             eta3 = pow(eta,3);
             eta4 = pow(eta,4);
             double noSpin = 0.2088669311744758 - 0.37138987533788487*eta + 6.510807976353186*eta2 - 31.330215053905395*eta3 + 55.45508989446867*eta4;
             double eqSpin = ((0.2393965714370633 + 1.6966740823756759*eta - 16.874355161681766*eta2 + 38.61300158832203*eta3)*S)/(1. - 0.633218538432246*S);
-            double uneqSpin = (chi1 - 1.*chi2)*(0.9088578269496244*pow(eta,2.5) + 15.619592332008951*(chi1 - 1.*chi2)*pow(eta,3.5))*delta;
+            double uneqSpin = pWF->dchi*(0.9088578269496244*pow(eta,2.5) + 15.619592332008951*pWF->dchi*pow(eta,3.5))*delta;
             total = noSpin + eqSpin + uneqSpin;
             break;
         }
-        default:{XLAL_ERROR_REAL8(XLAL_EINVAL,"Error in IMRPhenomXHM_RD_Phase_22_alpha2: version is not valid. Recommended version is 122019.");}
+        default:{XLAL_ERROR_REAL8(XLAL_EINVAL,"Error in IMRPhenomXHM_RD_Phase_22_alpha2: version % is not valid.", RDPhaseFlag);}
     }
     return total;
 }
 
-static double IMRPhenomXHM_RD_Phase_22_alphaL(double eta, double S, double chi1, double chi2, int RDPhaseFlag) {
-    UNUSED double total=0, delta=sqrt(1.- 4.*eta),eta2,eta3,eta4,S2;
+static double IMRPhenomXHM_RD_Phase_22_alphaL(IMRPhenomXWaveformStruct *pWF, int RDPhaseFlag) {
+    double total=0;
     switch (RDPhaseFlag){
         case 122019:{
+            double eta = pWF->eta;
+            double S = pWF->STotR;
+            double delta=sqrt(1.- 4.*eta),eta2,eta3,eta4,S2;
             eta2 = pow(eta,2);
             eta3 = pow(eta,3);
             eta4 = pow(eta,4);
             S2 = pow(S,2);
             double noSpin = eta*(-1.1926122248825484 + 2.5400257699690143*eta - 16.504334734464244*eta2 + 27.623649807617376*eta3);
             double eqSpin = eta3*S*(35.803988443700824 + 9.700178927988006*S - 77.2346297158916*S2) + eta*S*(0.1034526554654983 - 0.21477847929548569*S - 0.06417449517826644*S2) + eta2*S*(-4.7282481007397825 + 0.8743576195364632*S + 8.170616575493503*S2) + eta4*S*(-72.50310678862684 - 39.83460092417137*S + 180.8345521274853*S2);
-            double uneqSpin = (-0.7428134042821221*chi1*pow(eta,3.5) + 0.7428134042821221*chi2*pow(eta,3.5) + 17.588573345324154*pow(chi1,2)*pow(eta,4.5) - 35.17714669064831*chi1*chi2*pow(eta,4.5) + 17.588573345324154*pow(chi2,2)*pow(eta,4.5))*delta;
+            double uneqSpin = (-0.7428134042821221*pWF->chi1L*pow(eta,3.5) + 0.7428134042821221*pWF->chi2L*pow(eta,3.5) + 17.588573345324154*pow(pWF->chi1L,2)*pow(eta,4.5) - 35.17714669064831*pWF->chi1L*pWF->chi2L*pow(eta,4.5) + 17.588573345324154*pow(pWF->chi2L,2)*pow(eta,4.5))*delta;
             total = noSpin + eqSpin + uneqSpin;
             break;
         }
-        default:{XLAL_ERROR_REAL8(XLAL_EINVAL,"Error in IMRPhenomXHM_RD_Phase_22_alphaL: version is not valid. Recommended version is 122019.");}
+        default:{XLAL_ERROR_REAL8(XLAL_EINVAL,"Error in IMRPhenomXHM_RD_Phase_22_alphaL: version % is not valid.", RDPhaseFlag);}
     }
     return total;
 }
 
 /**************** 32 specific fits ***************/
-static double IMRPhenomXHM_RD_Phase_32_SpheroidalTimeShift(double eta, double S, double chi1, double chi2, UNUSED int RDPhaseFlag) {
-
-    double total,eta2,eta3,eta4,eta5,S2,S3,S4;
-    eta2 = pow(eta,2);
-    eta3 = pow(eta,3);
-    eta4 = pow(eta,4);
-    eta5 = pow(eta,5);
-    S2 = pow(S,2);
-    S3 = pow(S,3);
-    S4 = pow(S,4);
-    double noSpin = 11.851438981981772 + 167.95086712701223*eta - 4565.033758777737*eta2 + 61559.132976189896*eta3 - 364129.24735853914*eta4 + 739270.8814129328*eta5;
-    double eqSpin = (9.506768471271634 + 434.31707030999445*eta - 8046.364492927503*eta2 + 26929.677144312944*eta3)*S + (-5.949655484033632 - 307.67253970367034*eta + 1334.1062451631644*eta2 + 3575.347142399199*eta3)*S2 + (3.4881615575084797 - 2244.4613237912527*eta + 24145.932943269272*eta2 - 60929.87465551446*eta3)*S3 + (15.585154698977842 - 2292.778112523392*eta + 24793.809334683185*eta2 - 65993.84497923202*eta3)*S4;
-    double uneqSpin = 465.7904934097202*(chi1 - 1.*chi2)*sqrt(1. - 4.*eta)*eta2;
-    total = noSpin + eqSpin + uneqSpin;
-
+static double IMRPhenomXHM_RD_Phase_32_SpheroidalTimeShift(IMRPhenomXWaveformStruct *pWF, int RDPhaseFlag) {
+    double total;
+    switch (RDPhaseFlag){
+        case 122019:{
+            double eta = pWF->eta;
+            double S = pWF->STotR;
+            double eta2,eta3,eta4,eta5,S2,S3,S4;
+            eta2 = pow(eta,2);
+            eta3 = pow(eta,3);
+            eta4 = pow(eta,4);
+            eta5 = pow(eta,5);
+            S2 = pow(S,2);
+            S3 = pow(S,3);
+            S4 = pow(S,4);
+            double noSpin = 11.851438981981772 + 167.95086712701223*eta - 4565.033758777737*eta2 + 61559.132976189896*eta3 - 364129.24735853914*eta4 + 739270.8814129328*eta5;
+            double eqSpin = (9.506768471271634 + 434.31707030999445*eta - 8046.364492927503*eta2 + 26929.677144312944*eta3)*S + (-5.949655484033632 - 307.67253970367034*eta + 1334.1062451631644*eta2 + 3575.347142399199*eta3)*S2 + (3.4881615575084797 - 2244.4613237912527*eta + 24145.932943269272*eta2 - 60929.87465551446*eta3)*S3 + (15.585154698977842 - 2292.778112523392*eta + 24793.809334683185*eta2 - 65993.84497923202*eta3)*S4;
+            double uneqSpin = 465.7904934097202*pWF->dchi*sqrt(1.-4.*eta)*eta2;
+            total = noSpin + eqSpin + uneqSpin;
+            break;
+        }
+        case 122022:{
+            double eta = pWF->eta;
+            double delta = pWF->delta;
+            double S = pWF->STotR;
+            double chidiff = pWF->dchi_half;
+            double eta1 = eta;
+            double eta2 = eta1 * eta1;
+            double eta3 = eta1 * eta2;
+            double eta4 = eta1 * eta3;
+            double S1 = S;
+            double chidiff1 = chidiff;
+            total = chidiff1*delta*(-3437.4083682807154*eta2 + 29349.322789666763*eta3 - 46822.26853496922*eta4) + S1*(18.280316689743625*(46.16185108285708*eta1 - 515.3588338752849*eta2 + 1475.462268010926*eta3) + 2.1970246269696427*(370.70040479593024*eta1 - 4329.153306191607*eta2 + 12065.631680744644*eta3)*S1) + (12.080898026205173 - 79.10914761468462*eta1 - 89.82426456495799*eta2 + 915.6864093792078*eta3)*pow(1 - 9.443713298364061*eta1 + 22.353898754970686*eta2,-1);
+            break;
+        }
+        default:{XLAL_ERROR_REAL8(XLAL_EINVAL,"Error in IMRPhenomXHM_RD_Phase_32_SpheroidalTimeShift: version %i is not valid.", RDPhaseFlag);}
+    }
     return total;
 }
 
-static double IMRPhenomXHM_RD_Phase_32_SpheroidalPhaseShift(double eta, double S, double chi1, double chi2, UNUSED int RDPhaseFlag) {
-    double total,eta2,eta3,eta4,eta5,eta6,eta7,S2,S3,S4;
-    eta2 = pow(eta,2);
-    eta3 = pow(eta,3);
-    eta4 = pow(eta,4);
-    eta5 = pow(eta,5);
-    eta6 = pow(eta,6);
-    eta7 = pow(eta,7);
-    S2 = pow(S,2);
-    S3 = pow(S,3);
-    S4 = pow(S,4);
-    double noSpin = -1.3328895897490733 - 22.209549522908667*eta + 1056.2426481245027*eta2 - 21256.376324666326*eta3 + 246313.12887984765*eta4 - 1.6312968467540336e6*eta5 + 5.614617173188322e6*eta6 - 7.612233821752137e6*eta7;
-    double eqSpin = (S*(-1.622727240110213 + 0.9960210841611344*S - 1.1239505323267036*S2 - 1.9586085340429995*S3 + eta2*(196.7055281997748 + 135.25216875394943*S + 1086.7504825459278*S2 + 546.6246807461155*S3 - 312.1010566468068*S4) + 0.7638287749489343*S4 + eta*(-47.475568056234245 - 35.074072557604445*S - 97.16014978329918*S2 - 34.498125910065156*S3 + 24.02858084544326*S4) + eta3*(62.632493533037625 - 22.59781899512552*S - 2683.947280170815*S2 - 1493.177074873678*S3 + 805.0266029288334*S4)))/(-2.950271397057221 + 1.*S);
-    double uneqSpin = (sqrt(1. - 4.*eta)*(chi2*pow(eta,2.5)*(88.56162028006072 - 30.01812659282717*S) + chi2*eta2*(43.126266433486435 - 14.617728550838805*S) + chi1*eta2*(-43.126266433486435 + 14.617728550838805*S) + chi1*pow(eta,2.5)*(-88.56162028006072 + 30.01812659282717*S)))/(-2.950271397057221 + 1.*S);
-    total = noSpin + eqSpin + uneqSpin;
-
+static double IMRPhenomXHM_RD_Phase_32_SpheroidalPhaseShift(IMRPhenomXWaveformStruct *pWF, int RDPhaseFlag) {
+    double total;
+    switch (RDPhaseFlag){
+        case 122019:
+        {
+            double eta = pWF->eta;
+            double S = pWF->STotR;
+            double eta2,eta3,eta4,eta5,eta6,eta7,S2,S3,S4;
+            eta2 = pow(eta,2);
+            eta3 = pow(eta,3);
+            eta4 = pow(eta,4);
+            eta5 = pow(eta,5);
+            eta6 = pow(eta,6);
+            eta7 = pow(eta,7);
+            S2 = pow(S,2);
+            S3 = pow(S,3);
+            S4 = pow(S,4);
+            double noSpin = -1.3328895897490733 - 22.209549522908667*eta + 1056.2426481245027*eta2 - 21256.376324666326*eta3 + 246313.12887984765*eta4 - 1.6312968467540336e6*eta5 + 5.614617173188322e6*eta6 - 7.612233821752137e6*eta7;
+            double eqSpin = (S*(-1.622727240110213 + 0.9960210841611344*S - 1.1239505323267036*S2 - 1.9586085340429995*S3 + eta2*(196.7055281997748 + 135.25216875394943*S + 1086.7504825459278*S2 + 546.6246807461155*S3 - 312.1010566468068*S4) + 0.7638287749489343*S4 + eta*(-47.475568056234245 - 35.074072557604445*S - 97.16014978329918*S2 - 34.498125910065156*S3 + 24.02858084544326*S4) + eta3*(62.632493533037625 - 22.59781899512552*S - 2683.947280170815*S2 - 1493.177074873678*S3 + 805.0266029288334*S4)))/(-2.950271397057221 + 1.*S);
+            double uneqSpin = (sqrt(1.-4.*eta)*(pWF->chi2L*pow(eta,2.5)*(88.56162028006072 - 30.01812659282717*S) + pWF->chi2L*eta2*(43.126266433486435 - 14.617728550838805*S) + pWF->chi1L*eta2*(-43.126266433486435 + 14.617728550838805*S) + pWF->chi1L*pow(eta,2.5)*(-88.56162028006072 + 30.01812659282717*S)))/(-2.950271397057221 + 1.*S);
+            total = noSpin + eqSpin + uneqSpin;
+            break;
+        }
+        case 122022:{
+            double eta = pWF->eta;
+            double delta = pWF->delta;
+            double S = pWF->chiPNHat;
+            double chidiff = pWF->dchi_half;
+            double eta1 = eta;
+            double eta2 = eta1 * eta1;
+            double eta3 = eta1 * eta2;
+            double eta4 = eta1 * eta3;
+            double eta5 = eta1 * eta4;
+            double S1 = S;
+            double S2 = S1 * S1;
+            double chidiff1 = chidiff;
+            double chidiff2 = chidiff1 * chidiff1;
+            total = chidiff1*delta*(-4055.661463620154*eta3 + 48053.79215999518*eta4 - 126644.96534635697*eta5) + chidiff2*(1489.2939046368886*eta3 - 11333.726790227513*eta4 + 21470.681301598026*eta5) + S1*(-0.09759112086805133*(-3.6379140102351064 + 510.0158912180661*eta1 - 12528.715040030444*eta2 + 82416.24893999398*eta3 - 161740.0041427807*eta4) - 0.20117612026208484*(-5.676646590653427 + 183.78422258983136*eta1 - 3807.617101722895*eta2 + 24219.360141326677*eta3 - 45892.369216999985*eta4)*S1 + 0.06537048555519695*(21.388069487574892 + 408.2245599781871*eta1 - 9652.666650065075*eta2 + 57782.086859487965*eta3 - 110112.73697613904*eta4)*S2) + (-1.3903824533899325 + 13.761709564309667*eta1 - 10.633427224975128*eta2 - 263.01839936998965*eta3 + 736.1912896690361*eta4)*pow(1 - 9.458921853648649*eta1 + 22.932673653997934*eta2,-1);
+            break;
+        }
+            default:{XLAL_ERROR_REAL8(XLAL_EINVAL,"Error in IMRPhenomXHM_RD_Phase_32_SpheroidalPhaseShift: version %i is not valid.", RDPhaseFlag);}
+    }
     return total;
 }
 
 // collocation points
-static double IMRPhenomXHM_Ringdown_Phase_32_p1(double eta, double S, double chi1, double chi2, UNUSED int RingdownPhaseFlag) {
-    double total,eta2,eta3,eta4,eta5,S2,S3,S4,S5;
-    eta2 = pow(eta,2);
-    eta3 = pow(eta,3);
-    eta4 = pow(eta,4);
-    eta5 = pow(eta,5);
-    S2 = pow(S,2);
-    S3 = pow(S,3);
-    S4 = pow(S,4);
-    S5 = pow(S,5);
-    double noSpin = 3169.372056189274 + 426.8372805022653*eta - 12569.748101922158*eta2 + 149846.7281073725*eta3 - 817182.2896823225*eta4 + 1.5674053633767858e6*eta5;
-    double eqSpin = (19.23408352151287 - 1762.6573670619173*eta + 7855.316419853637*eta2 - 3785.49764771212*eta3)*S + (-42.88446003698396 + 336.8340966473415*eta - 5615.908682338113*eta2 + 20497.5021807654*eta3)*S2 + (13.918237996338371 + 10145.53174542332*eta - 91664.12621864353*eta2 + 201204.5096556517*eta3)*S3 + (-24.72321125342808 - 4901.068176970293*eta + 53893.9479532688*eta2 - 139322.02687945773*eta3)*S4 + (-61.01931672442576 - 16556.65370439302*eta + 162941.8009556697*eta2 - 384336.57477596396*eta3)*S5;
-    double uneqSpin = (chi1 - 1.*chi2)*sqrt(1. - 4.*eta)*eta2*(641.2473192044652 - 1600.240100295189*chi1*eta + 1600.240100295189*chi2*eta + 13275.623692212472*eta*S);
-    total = noSpin + eqSpin + uneqSpin;
-
+static double IMRPhenomXHM_RD_Phase_32_p1(IMRPhenomXWaveformStruct *pWF, int RDPhaseFlag) {
+    double total;
+    switch (RDPhaseFlag){
+        case 122019:{
+            double eta = pWF->eta;
+            double S = pWF->STotR;
+            double eta2,eta3,eta4,eta5,S2,S3,S4,S5;
+            eta2 = pow(eta,2);
+            eta3 = pow(eta,3);
+            eta4 = pow(eta,4);
+            eta5 = pow(eta,5);
+            S2 = pow(S,2);
+            S3 = pow(S,3);
+            S4 = pow(S,4);
+            S5 = pow(S,5);
+            double noSpin = 3169.372056189274 + 426.8372805022653*eta - 12569.748101922158*eta2 + 149846.7281073725*eta3 - 817182.2896823225*eta4 + 1.5674053633767858e6*eta5;
+            double eqSpin = (19.23408352151287 - 1762.6573670619173*eta + 7855.316419853637*eta2 - 3785.49764771212*eta3)*S + (-42.88446003698396 + 336.8340966473415*eta - 5615.908682338113*eta2 + 20497.5021807654*eta3)*S2 + (13.918237996338371 + 10145.53174542332*eta - 91664.12621864353*eta2 + 201204.5096556517*eta3)*S3 + (-24.72321125342808 - 4901.068176970293*eta + 53893.9479532688*eta2 - 139322.02687945773*eta3)*S4 + (-61.01931672442576 - 16556.65370439302*eta + 162941.8009556697*eta2 - 384336.57477596396*eta3)*S5;
+            double uneqSpin = pWF->dchi*sqrt(1.-4.*eta)*eta2*(641.2473192044652 - 1600.240100295189*pWF->chi1L*eta + 1600.240100295189*pWF->chi2L*eta + 13275.623692212472*eta*S);
+            total = noSpin + eqSpin + uneqSpin;
+            break;
+        }
+            case 122022:{
+            double eta = pWF->eta;
+            double delta = pWF->delta;
+            double S = pWF->STotR;
+            double chidiff = pWF->dchi_half;
+            double eta1 = eta;
+            double eta2 = eta1 * eta1;
+            double eta3 = eta1 * eta2;
+            double eta4 = eta1 * eta3;
+            double S1 = S;
+            double S2 = S1 * S1;
+            double chidiff1 = chidiff;
+            total = 3221.932636435056 - 134.59521937837278*eta1 + chidiff1*delta*(319.06177738567885*eta2 - 20578.40007594641*eta3 + 101859.1659970414*eta4) + S1*(24.059115241154707*(436.41245673494626*eta2 - 2938.503437122471*eta3 + 5027.414440730744*eta4) + 21.848741292340005*(1251.706577839354*eta2 - 14171.490147583942*eta3 + 36914.6553449061*eta4)*S1 + 15.901300902033508*(-149.2789474539545*eta2 + 3483.608736789833*eta3 - 11289.97178789606*eta4)*S2)*pow(-1.803337035190313 + S1,-1) - 0.012868288384497346*pow(0.000187943994873322 + pow(-0.1923690355128322 + eta1,2),-1);
+            break;
+        }
+        default:{XLAL_ERROR_REAL8(XLAL_EINVAL,"Error in IMRPhenomXHM_RD_Phase_32_p1: version % is not valid.", RDPhaseFlag);}
+    }
     return total;
 }
 // collocation points
-static double IMRPhenomXHM_Ringdown_Phase_32_p2(double eta, double S, double chi1, double chi2, UNUSED int RingdownPhaseFlag) {
-    double total,eta2,eta3,S2,S3,S4;
-    eta2 = pow(eta,2);
-    eta3 = pow(eta,3);
-    S2 = pow(S,2);
-    S3 = pow(S,3);
-    S4 = pow(S,4);
-    double noSpin = 3131.0260952676376 + 206.09687819102305*eta - 2636.4344627081873*eta2 + 7475.062269742079*eta3;
-    double eqSpin = (49.90874152040307 - 691.9815135740145*eta - 434.60154548208334*eta2 + 10514.68111669422*eta3)*S + (97.3078084654917 - 3458.2579971189534*eta + 26748.805404989867*eta2 - 56142.13736008524*eta3)*S2 + (-132.49105074500454 + 429.0787542102207*eta + 7269.262546204149*eta2 - 27654.067482558712*eta3)*S3 + (-227.8023564332453 + 5119.138772157134*eta - 34444.2579678986*eta2 + 69666.01833764123*eta3)*S4;
-    double uneqSpin = 477.51566939885424*(chi1 - 1.*chi2)*sqrt(1. - 4.*eta)*eta2;
-    total = noSpin + eqSpin + uneqSpin;
-
+static double IMRPhenomXHM_RD_Phase_32_p2(IMRPhenomXWaveformStruct *pWF, int RDPhaseFlag) {
+    double total;
+    switch (RDPhaseFlag){
+        case 122019:{
+            double eta = pWF->eta;
+            double S = pWF->STotR;
+            double eta2,eta3,S2,S3,S4;
+            eta2 = pow(eta,2);
+            eta3 = pow(eta,3);
+            S2 = pow(S,2);
+            S3 = pow(S,3);
+            S4 = pow(S,4);
+            double noSpin = 3131.0260952676376 + 206.09687819102305*eta - 2636.4344627081873*eta2 + 7475.062269742079*eta3;
+            double eqSpin = (49.90874152040307 - 691.9815135740145*eta - 434.60154548208334*eta2 + 10514.68111669422*eta3)*S + (97.3078084654917 - 3458.2579971189534*eta + 26748.805404989867*eta2 - 56142.13736008524*eta3)*S2 + (-132.49105074500454 + 429.0787542102207*eta + 7269.262546204149*eta2 - 27654.067482558712*eta3)*S3 + (-227.8023564332453 + 5119.138772157134*eta - 34444.2579678986*eta2 + 69666.01833764123*eta3)*S4;
+            double uneqSpin = 477.51566939885424*pWF->dchi*sqrt(1.-4.*eta)*eta2;
+            total = noSpin + eqSpin + uneqSpin;
+            break;
+        }
+            case 122022:{
+            double eta = pWF->eta;
+            double delta = pWF->delta;
+            double S = pWF->STotR;
+            double chidiff = pWF->dchi_half;
+            double eta1 = eta;
+            double eta2 = eta1 * eta1;
+            double eta3 = eta1 * eta2;
+            double eta4 = eta1 * eta3;
+            double S1 = S;
+            double chidiff1 = chidiff;
+            total = 3169.5772463611165 + 56.56534589293562*eta1 - 863.5731390762933*eta2 + 2693.8619211321557*eta3 + chidiff1*delta*(-2818.2944800258847*eta2 + 15684.658457287562*eta3 + 14379.128341035908*eta4) + S1*(-0.16388886708177886*(334.30009385854424*eta2 - 154749.10305716714*eta3 + 613903.6107269318*eta4) + 11.950465013745157*(1079.481585746054*eta2 - 11981.85336876442*eta3 + 30911.708103120814*eta4)*S1)*pow(-1.169876031327984 + S1,-1) - 0.009425837438775205*pow(0.00016960223009674388 + pow(-0.20083535429185695 + eta1,2),-1);
+            break;
+        }
+        default:{XLAL_ERROR_REAL8(XLAL_EINVAL,"Error in IMRPhenomXHM_RD_Phase_32_p2: version % is not valid.", RDPhaseFlag);}
+    }
     return total;
 }
 // collocation points
-static double IMRPhenomXHM_Ringdown_Phase_32_p3(double eta, double S, double chi1, double chi2, UNUSED int RingdownPhaseFlag) {
-    double total,eta2,eta3,S2,S3,S4;
-    eta2 = pow(eta,2);
-    eta3 = pow(eta,3);
-    S2 = pow(S,2);
-    S3 = pow(S,3);
-    S4 = pow(S,4);
-    double noSpin = 3082.803556599222 + 76.94679795837645*eta - 586.2469821978381*eta2 + 977.6115755788503*eta3;
-    double eqSpin = (45.08944710349874 - 807.7353772747749*eta + 1775.4343704616288*eta2 + 2472.6476419567534*eta3)*S + (95.57355060136699 - 2224.9613131172046*eta + 13821.251641893134*eta2 - 25583.314298758105*eta3)*S2 + (-144.96370424517866 + 2268.4693587493093*eta - 10971.864789147161*eta2 + 16259.911572457446*eta3)*S3 + (-227.8023564332453 + 5119.138772157134*eta - 34444.2579678986*eta2 + 69666.01833764123*eta3)*S4;
-    double uneqSpin = 378.2359918274837*(chi1 - 1.*chi2)*sqrt(1. - 4.*eta)*eta2;
-    total = noSpin + eqSpin + uneqSpin;
-
+static double IMRPhenomXHM_RD_Phase_32_p3(IMRPhenomXWaveformStruct *pWF, int RDPhaseFlag) {
+    double total;
+    switch (RDPhaseFlag){
+        case 122019:{
+            double eta = pWF->eta;
+            double S = pWF->STotR;
+            double eta2,eta3,S2,S3,S4;
+            eta2 = pow(eta,2);
+            eta3 = pow(eta,3);
+            S2 = pow(S,2);
+            S3 = pow(S,3);
+            S4 = pow(S,4);
+            double noSpin = 3082.803556599222 + 76.94679795837645*eta - 586.2469821978381*eta2 + 977.6115755788503*eta3;
+            double eqSpin = (45.08944710349874 - 807.7353772747749*eta + 1775.4343704616288*eta2 + 2472.6476419567534*eta3)*S + (95.57355060136699 - 2224.9613131172046*eta + 13821.251641893134*eta2 - 25583.314298758105*eta3)*S2 + (-144.96370424517866 + 2268.4693587493093*eta - 10971.864789147161*eta2 + 16259.911572457446*eta3)*S3 + (-227.8023564332453 + 5119.138772157134*eta - 34444.2579678986*eta2 + 69666.01833764123*eta3)*S4;
+            double uneqSpin = 378.2359918274837*pWF->dchi*sqrt(1.-4.*eta)*eta2;
+            total = noSpin + eqSpin + uneqSpin;
+            break;
+        }
+            case 122022:{
+            double eta = pWF->eta;
+            double delta = pWF->delta;
+            double S = pWF->STotR;
+            double chidiff = pWF->dchi_half;
+            double eta1 = eta;
+            double eta2 = eta1 * eta1;
+            double eta3 = eta1 * eta2;
+            double eta4 = eta1 * eta3;
+            double eta5 = eta1 * eta4;
+            double eta6 = eta1 * eta5;
+            double S1 = S;
+            double chidiff1 = chidiff;
+            total = 3119.6603946770488 + 168.61554447853712*eta1 - 1777.6654596491376*eta2 + 5037.407962552042*eta3 + chidiff1*delta*(45693.135566736484*eta2 - 789332.4959926775*eta3 + 4.460496312695218e6*eta4 - 8.176309211912101e6*eta5) + chidiff1*delta*(7840.121424232572*eta2 - 47166.09840761356*eta3 + 66597.52917033392*eta4)*S1 + S1*(-6.019579546899472*(14538.163921822728*eta2 - 318911.4362763759*eta3 + 2.6041867832020866e6*eta4 - 9.288489508236282e6*eta5 + 1.2170972980338342e7*eta6) - 7.739304888898913*(11114.219992659659*eta2 - 231541.9569739445*eta3 + 1.8069370995120746e6*eta4 - 6.203273456127891e6*eta5 + 7.874294046591697e6*eta6)*S1) - 0.0003538235766427527*pow(8.2810517855422e-6 + pow(-0.2075868299995718 + eta1,2),-1);
+            break;
+        }
+        default:{XLAL_ERROR_REAL8(XLAL_EINVAL,"Error in IMRPhenomXHM_RD_Phase_32_p3: version % is not valid.", RDPhaseFlag);}
+    }
     return total;
 }
 // collocation points
-static double IMRPhenomXHM_Ringdown_Phase_32_p4(double eta, double S, double chi1, double chi2, UNUSED int RingdownPhaseFlag) {
-    double total,eta2,S2,S3,S4;
-    eta2 = pow(eta,2);
-    S2 = pow(S,2);
-    S3 = pow(S,3);
-    S4 = pow(S,4);
-    double noSpin = 3077.0657367004565 + 64.99844502520415*eta - 357.38692756785395*eta2;
-    double eqSpin = (34.793450080444714 - 986.7751755509875*eta - 9490.641676924794*pow(eta,3) + 5700.682624203565*eta2)*S + (57.38106384558743 - 1644.6690499868596*eta - 19906.416384606226*pow(eta,3) + 11008.881935880598*eta2)*S2 + (-126.02362949830213 + 3169.3397351803583*eta + 62863.79877094988*pow(eta,3) - 26766.730897942085*eta2)*S3 + (-169.30909412804587 + 4900.706039920717*eta + 95314.99988114933*pow(eta,3) - 41414.05689348732*eta2)*S4;
-    double uneqSpin = 390.5443469721231*(chi1 - 1.*chi2)*sqrt(1. - 4.*eta)*eta2;
-    total = noSpin + eqSpin + uneqSpin;
-
+static double IMRPhenomXHM_RD_Phase_32_p4(IMRPhenomXWaveformStruct *pWF, int RDPhaseFlag) {
+    double total;
+    switch (RDPhaseFlag){
+        case 122019:{
+            double eta = pWF->eta;
+            double S = pWF->STotR;
+            double eta2,S2,S3,S4;
+            eta2 = pow(eta,2);
+            S2 = pow(S,2);
+            S3 = pow(S,3);
+            S4 = pow(S,4);
+            double noSpin = 3077.0657367004565 + 64.99844502520415*eta - 357.38692756785395*eta2;
+            double eqSpin = (34.793450080444714 - 986.7751755509875*eta - 9490.641676924794*pow(eta,3) + 5700.682624203565*eta2)*S + (57.38106384558743 - 1644.6690499868596*eta - 19906.416384606226*pow(eta,3) + 11008.881935880598*eta2)*S2 + (-126.02362949830213 + 3169.3397351803583*eta + 62863.79877094988*pow(eta,3) - 26766.730897942085*eta2)*S3 + (-169.30909412804587 + 4900.706039920717*eta + 95314.99988114933*pow(eta,3) - 41414.05689348732*eta2)*S4;
+            double uneqSpin = 390.5443469721231*pWF->dchi*sqrt(1.-4.*eta)*eta2;
+            total = noSpin + eqSpin + uneqSpin;
+            break;
+        }
+            case 122022:{
+            double eta = pWF->eta;
+            double delta = pWF->delta;
+            double S = pWF->STotR;
+            double chidiff = pWF->dchi_half;
+            double eta1 = eta;
+            double eta2 = eta1 * eta1;
+            double eta3 = eta1 * eta2;
+            double eta4 = eta1 * eta3;
+            double eta5 = eta1 * eta4;
+            double eta6 = eta1 * eta5;
+            double eta7 = eta1 * eta6;
+            double S1 = S;
+            double chidiff1 = chidiff;
+            total = 3063.2702533356364 + 74.20321762511647*eta1 - 346.6653326379183*eta2 + chidiff1*delta*(2604.6711121030685*eta2 - 25322.83641432119*eta3 + 64521.907625802785*eta4) + 17.748987975469845*(6659.676835974436*eta2 - 207712.54687648916*eta3 + 2.5247192995989644e6*eta4 - 1.4825576629165621e7*eta5 + 4.215660954626601e7*eta6 - 4.662796037240443e7*eta7)*S1*pow(-1.2617538728082525 + S1,-1) - 2.211595095940034e-6*pow(-0.000010240443266599763 + pow(-0.17594819839300638 + eta1,2),-1);
+            break;
+        }
+        default:{XLAL_ERROR_REAL8(XLAL_EINVAL,"Error in IMRPhenomXHM_RD_Phase_32_p4: version % is not valid.", RDPhaseFlag);}
+    }
     return total;
 }
 
 
+static double IMRPhenomXHM_RD_Phase_32_p5(IMRPhenomXWaveformStruct *pWF, int RDPhaseFlag){
+	double total=0;
+	switch (RDPhaseFlag){
+        case 122022:{
+            double eta = pWF->eta;
+            double delta = pWF->delta;
+            double S = pWF->STotR;
+            double chidiff = pWF->dchi_half;
+            double eta1 = eta;
+            double eta2 = eta1 * eta1;
+            double eta3 = eta1 * eta2;
+            double eta4 = eta1 * eta3;
+            double eta5 = eta1 * eta4;
+            double eta6 = eta1 * eta5;
+            double eta7 = eta1 * eta6;
+            double S1 = S;
+            double chidiff1 = chidiff;
+            total = 3099.009925231132 - 5.823302919769178*eta1 + chidiff1*delta*(1936.2628510750844*eta2 - 32280.62038532877*eta3 + 97943.49145078743*eta4) + 2.8281136508769498*(6856.762845446495*eta2 - 201653.94475043533*eta3 + 2.4217205751584964e6*eta4 - 1.4582166806161262e7*eta5 + 4.377208838391116e7*eta6 - 5.214533274483399e7*eta7)*S1*pow(-1.0624647822393556 + S1,-1);
+            break;
+        }
+    default:{XLAL_ERROR_REAL8(XLAL_EINVAL,"Error in IMRPhenomXHM_RD_Phase_32_p5: version % is not valid.", RDPhaseFlag);}
+  }
+  return total;
+}
+
+/* End of Phase Parameter Space Fits */
+
 /**************  ANSATZ PHASE DERIVATIVE **************/
 
 static double IMRPhenomXHM_RD_Phase_Ansatz(double ff, IMRPhenomX_UsefulPowers *powers_of_f,IMRPhenomXHMWaveformStruct *pWFHM,  IMRPhenomXHMPhaseCoefficients *pPhase){
 
-    double invf2 = powers_of_f->m_two;
     double frd   = pWFHM->fRING;
     double fda   = pWFHM->fDAMP;
     double dphaseRD;
@@ -550,17 +1393,28 @@ static double IMRPhenomXHM_RD_Phase_Ansatz(double ff, IMRPhenomX_UsefulPowers *p
             /*  rescaling of the 22 ansatz -- used for (21),(33),(44) */
             /*ansatz:
              alpha0 + ((fRDlm^2) alpha2)/(f^2)  + alphaL*(fdamplm)/((fdamplm)^2 + (f - fRDlm)^2)*/
-            dphaseRD = ( pPhase->alpha0 +  frd*frd*(pPhase->alpha2)*invf2 + ( (pPhase->alphaL)* fda/(fda*fda +(ff - frd)*(ff - frd)) ) );
+            dphaseRD = ( pPhase->alpha0 +  frd*frd*(pPhase->alpha2)*powers_of_f->m_two + ( (pPhase->alphaL)* fda/(fda*fda +(ff - frd)*(ff - frd)) ) );
             break;
 
         }
         case 1:
         {
             /*  calibration of spheroidal ringdown waveform for (32) */
-            /* ansatz: alpha0 + (alpha2)/(f^2)+ (alpha4)/(f^4)  + alphaL*(fdamplm)/((fdamplm)^2 + (f - fRDlm)^2)*/
-            double invf4 = powers_of_f->m_four;
-            dphaseRD = ( pPhase->alpha0_S +  (pPhase->alpha2_S)*invf2 + (pPhase->alpha4_S)*invf4 +( (pPhase->alphaL_S)* fda/(fda*fda +(ff - frd)*(ff - frd)) ) );
-            break;
+
+            if(pWFHM->IMRPhenomXHMRingdownPhaseVersion == 122019){
+                /* ansatz: alpha0 + (alpha2)/(f^2)+ (alpha4)/(f^4)  + alphaL*(fdamplm)/((fdamplm)^2 + (f - fRDlm)^2)*/
+                dphaseRD = ( pPhase->alpha0_S +  (pPhase->alpha2_S)*powers_of_f->m_two + (pPhase->alpha4_S)*powers_of_f->m_four +( (pPhase->alphaL_S)* fda/(fda*fda +(ff - frd)*(ff - frd)) ) );
+            }
+            else{ // FIXME: 1/eta???
+              if(pWFHM->fPhaseRDflat > 0 && IMRPhenomX_StepFuncBool(ff, pWFHM->fPhaseRDflat)){
+                dphaseRD = pPhase->RDCoefficient[5] + pPhase->RDCoefficient[6] * powers_of_f->m_five;
+              }
+              else{
+                /* ansatz: a0 + a1/f + a2/f^2 + a3/f^4  + a4*fdamplm/(fdamplm^2 + (f - fRDlm)^2) */
+                dphaseRD = ( pPhase->RDCoefficient[0] +  pPhase->RDCoefficient[1] * powers_of_f->m_one + pPhase->RDCoefficient[2] * powers_of_f->m_two + pPhase->RDCoefficient[3] * powers_of_f->m_four + pPhase->RDCoefficient[4]*fda / (fda*fda + (ff - frd)*(ff - frd))  );
+              }
+            }
+        break;
         }
         default:
         {XLAL_ERROR(XLAL_EDOM, "Error in IMRPhenomXHM_RD_Phase_Ansatz: version is not valid. Use version 0 for modes (2,1),(3,3),(4,4) and 1 for (3,2).\n");}
@@ -590,9 +1444,22 @@ static double IMRPhenomXHM_RD_Phase_AnsatzInt(double ff, IMRPhenomX_UsefulPowers
         case 1:
         {
             /*  calibration of spheroidal ringdown waveform for (32) */
-            /* ansatz: f alpha0 - (alpha4)/(3 f^3) - (alpha2)/f + alphaL ArcTan[(f - fRDlm)/fdamplm]*/
             double invf3 = powers_of_f->m_three;
-            phaseRD = pPhase->phi0_S+pPhase->alpha0_S*ff -(pPhase->alpha2_S)*invf -1./3.*(pPhase->alpha4_S)*invf3 +(pPhase->alphaL_S)* atan((ff-frd)/fda);
+
+            if(pWFHM->IMRPhenomXHMRingdownPhaseVersion == 122019){
+                /* ansatz: f alpha0 - (alpha4)/(3 f^3) - (alpha2)/f + alphaL ArcTan[(f - fRDlm)/fdamplm]*/
+                phaseRD = pPhase->phi0_S+pPhase->alpha0_S*ff -(pPhase->alpha2_S)*invf -1./3.*(pPhase->alpha4_S)*invf3 +(pPhase->alphaL_S)* atan((ff-frd)/fda);
+            }
+            else{
+              if(pWFHM->fPhaseRDflat > 0 && IMRPhenomX_StepFuncBool(ff, pWFHM->fPhaseRDflat)){
+                // a + b / f^5
+                phaseRD = pPhase->phi0_S + pPhase->RDCoefficient[7] + pPhase->RDCoefficient[5]*ff - 0.25 * pPhase->RDCoefficient[6] * powers_of_f->m_four;
+              }
+              else{
+                /* ansatz: f a0 + a1 Log(f) - a2/f - a3/(3f^3)  + a4*ArcTan[(f - fRDlm)/fdamplm] */
+                phaseRD = pPhase->phi0_S + pPhase->RDCoefficient[0]*ff + pPhase->RDCoefficient[1]*powers_of_f->log - pPhase->RDCoefficient[2]*invf - 1/3.*pPhase->RDCoefficient[3]*invf3 + pPhase->RDCoefficient[4]*atan( (ff-frd)/fda );
+              }
+            }
             break;
         }
         default:
@@ -600,3 +1467,39 @@ static double IMRPhenomXHM_RD_Phase_AnsatzInt(double ff, IMRPhenomX_UsefulPowers
     }
     return phaseRD;
 }
+
+static double IMRPhenomXHM_RD_Phase_DerAnsatz(double ff, IMRPhenomX_UsefulPowers *powers_of_f,IMRPhenomXHMWaveformStruct *pWFHM,  IMRPhenomXHMPhaseCoefficients *pPhase){
+
+    double frd   = pWFHM->fRING;
+    double fda   = pWFHM->fDAMP;
+    double ddphaseRD;
+    
+
+    switch ( pWFHM->MixingOn )
+    {
+        case 0:
+        {
+            /*  rescaling of the 22 ansatz -- used for (21),(33),(44) */
+            /*ansatz:
+             alpha0 + ((fRDlm^2) alpha2)/(f^2)  + alphaL*(fdamplm)/((fdamplm)^2 + (f - fRDlm)^2)*/
+            ddphaseRD = -2*frd*frd*(pPhase->alpha2)*powers_of_f->m_three + -2*pPhase->alphaL* fda *(ff-frd)/pow(fda*fda +(ff - frd)*(ff - frd), 2) ;
+            break;
+        }
+        case 1:
+        {
+            /*  calibration of spheroidal ringdown waveform for (32) */
+            if(pWFHM->IMRPhenomXHMRingdownPhaseVersion == 122019){
+                /* ansatz: alpha0 + (alpha2)/(f^2)+ (alpha4)/(f^4)  + alphaL*(fdamplm)/((fdamplm)^2 + (f - fRDlm)^2)*/
+                ddphaseRD = -2*pPhase->alpha2_S*powers_of_f->m_three - 4*(pPhase->alpha4_S)*powers_of_f->m_five - 2*( pPhase->alphaL_S* fda * (ff-frd)/pow(fda*fda +(ff - frd)*(ff - frd), 2) ) ;
+            }
+            else{ 
+                /* ansatz: a0 + a1/f + a2/f^2 + a3/f^4  + a4*fdamplm/(fdamplm^2 + (f - fRDlm)^2) */
+                ddphaseRD = ( - pPhase->RDCoefficient[1] * powers_of_f->m_two - 2 * pPhase->RDCoefficient[2] * powers_of_f->m_three - 4 * pPhase->RDCoefficient[3] * powers_of_f->m_five - 2 * pPhase->RDCoefficient[4]*fda*(ff-frd) / pow(fda*fda + (ff - frd)*(ff - frd), 2)  );
+            }
+            break;
+        }
+        default:
+        {XLAL_ERROR(XLAL_EDOM, "Error in IMRPhenomXHM_RD_Phase_Ansatz: version is not valid. Use version 0 for modes (2,1),(3,3),(4,4) and 1 for (3,2).\n");}
+    }
+    return ddphaseRD;
+}
diff --git a/lalsimulation/lib/LALSimIMRPhenomXHM_ringdown.h b/lalsimulation/lib/LALSimIMRPhenomXHM_ringdown.h
index 8281caa648e39b78efce0f63ffe022d0768ba869..e9b1191d93d66a76a1b522025d747004860a2cd8 100644
--- a/lalsimulation/lib/LALSimIMRPhenomXHM_ringdown.h
+++ b/lalsimulation/lib/LALSimIMRPhenomXHM_ringdown.h
@@ -38,53 +38,77 @@ extern "C" {
 #include "LALSimIMRPhenomXHM_structs.h"
 
 
-    //----AMPLITUDE----
-
-    //Fits of the ringdown coefficients over parameter space
-    static double IMRPhenomXHM_RD_Amp_21_alambda(double eta, double S, double chi1, double chi2, int RDAmpFlag);
-    static double IMRPhenomXHM_RD_Amp_21_lambda(double eta, double S, double chi1, double chi2, int RDAmpFlag);
-    static double IMRPhenomXHM_RD_Amp_33_alambda(double eta, double S, double chi1, double chi2, int RDAmpFlag);
-    static double IMRPhenomXHM_RD_Amp_33_lambda(double eta, double S, double chi1, double chi2, int RDAmpFlag);
-    static double IMRPhenomXHM_RD_Amp_32_alambda(double eta, double S, double chi1, double chi2, int RDAmpFlag);
-    static double IMRPhenomXHM_RD_Amp_32_lambda(double eta, double S, double chi1, double chi2, int RDAmpFlag);
-    static double IMRPhenomXHM_RD_Amp_44_alambda(double eta, double S, double chi1, double chi2, int RDAmpFlag);
-    static double IMRPhenomXHM_RD_Amp_44_lambda(double eta, double S, double chi1, double chi2, int RDAmpFlag);
-    static double IMRPhenomXHM_RD_Amp_21_sigma(double eta, double S, double chi1, double chi2, int RDAmpFlag);
-    static double IMRPhenomXHM_RD_Amp_33_sigma(double eta, double S, double chi1, double chi2, int RDAmpFlag);// currently constant
-    static double IMRPhenomXHM_RD_Amp_32_sigma(double eta, double S, double chi1, double chi2, int RDAmpFlag);// currently constant
-    static double IMRPhenomXHM_RD_Amp_44_sigma(double eta, double S, double chi1, double chi2, int RDAmpFlag);// currently constant
-
-    //ansatz, and its derivative: analytical for no mixing and numerical for mixing
-    static double IMRPhenomXHM_RD_Amp_Ansatz(double ff, IMRPhenomXHMWaveformStruct *pWF,  IMRPhenomXHMAmpCoefficients *pAmp);
-    static double IMRPhenomXHM_RD_Amp_DAnsatz(double ff, IMRPhenomXHMWaveformStruct *pWF, IMRPhenomXHMAmpCoefficients *pAmp);
-    static double IMRPhenomXHM_RD_Amp_NDAnsatz(double ff, IMRPhenomXHMAmpCoefficients *pAmp,  IMRPhenomXHMPhaseCoefficients *pPhase, IMRPhenomXHMWaveformStruct *pWFHM, IMRPhenomXAmpCoefficients *pAmp22,  IMRPhenomXPhaseCoefficients *pPhase22, IMRPhenomXWaveformStruct *pWF22);
-
-    // Feeding the ansatz with the coefficients is how we get the final reconstruction
-
-    //veto
-    static void IMRPhenomXHM_Ringdown_Amplitude_Veto(double *pV2, double *pV3, double V4, IMRPhenomXHMWaveformStruct *pWFHM, IMRPhenomXWaveformStruct *pWF22);
-
-
-    //----PHASE-----
-
-    // no mixing fits
-    static double IMRPhenomXHM_RD_Phase_22_alpha2(double eta, double S, double chi1, double chi2, int RDPhaseFlag);
-    static double IMRPhenomXHM_RD_Phase_22_alphaL(double eta, double S, double chi1, double chi2, int RDPhaseFlag);
-    // 32 specific fits
-    static double IMRPhenomXHM_RD_Phase_32_SpheroidalTimeShift(double eta, double S, double chi1, double chi2, int RDPhaseFlag);
-    static double IMRPhenomXHM_RD_Phase_32_SpheroidalPhaseShift(double eta, double S, double chi1, double chi2, int RDPhaseFlag);
-    static double IMRPhenomXHM_Ringdown_Phase_32_p1(double eta, double S, double chi1, double chi2, int RingdownPhaseFlag);
-    static double IMRPhenomXHM_Ringdown_Phase_32_p2(double eta, double S, double chi1, double chi2, int RingdownPhaseFlag);
-    static double IMRPhenomXHM_Ringdown_Phase_32_p3(double eta, double S, double chi1, double chi2, int RingdownPhaseFlag);
-    static double IMRPhenomXHM_Ringdown_Phase_32_p4(double eta, double S, double chi1, double chi2, int RingdownPhaseFlag);
-
-    //ansatz
-    static double IMRPhenomXHM_RD_Phase_Ansatz(double ff,IMRPhenomX_UsefulPowers *powers_of_f, IMRPhenomXHMWaveformStruct *pWFHM,  IMRPhenomXHMPhaseCoefficients *pPhase);
-    static double IMRPhenomXHM_RD_Phase_AnsatzInt(double ff, IMRPhenomX_UsefulPowers *powers_of_f,IMRPhenomXHMWaveformStruct *pWFHM,  IMRPhenomXHMPhaseCoefficients *pPhase);
+//----AMPLITUDE----
+
+//Fits of the ringdown coefficients over parameter space
+static double IMRPhenomXHM_RD_Amp_21_alambda(IMRPhenomXWaveformStruct *pWF, int RDAmpFlag);
+static double IMRPhenomXHM_RD_Amp_21_lambda(IMRPhenomXWaveformStruct *pWF, int RDAmpFlag);
+static double IMRPhenomXHM_RD_Amp_33_alambda(IMRPhenomXWaveformStruct *pWF, int RDAmpFlag);
+static double IMRPhenomXHM_RD_Amp_33_lambda(IMRPhenomXWaveformStruct *pWF, int RDAmpFlag);
+static double IMRPhenomXHM_RD_Amp_32_alambda(IMRPhenomXWaveformStruct *pWF, int RDAmpFlag);
+static double IMRPhenomXHM_RD_Amp_32_lambda(IMRPhenomXWaveformStruct *pWF, int RDAmpFlag);
+static double IMRPhenomXHM_RD_Amp_44_alambda(IMRPhenomXWaveformStruct *pWF, int RDAmpFlag);
+static double IMRPhenomXHM_RD_Amp_44_lambda(IMRPhenomXWaveformStruct *pWF, int RDAmpFlag);
+static double IMRPhenomXHM_RD_Amp_21_sigma(IMRPhenomXWaveformStruct *pWF, int RDAmpFlag);
+static double IMRPhenomXHM_RD_Amp_33_sigma(IMRPhenomXWaveformStruct *pWF, int RDAmpFlag);// currently constant
+static double IMRPhenomXHM_RD_Amp_32_sigma(IMRPhenomXWaveformStruct *pWF, int RDAmpFlag);// currently constant
+static double IMRPhenomXHM_RD_Amp_44_sigma(IMRPhenomXWaveformStruct *pWF, int RDAmpFlag);// currently constant
+static double IMRPhenomXHM_RD_Amp_21_rdcp1(IMRPhenomXWaveformStruct *pWF, int RDAmpFlag);
+static double IMRPhenomXHM_RD_Amp_21_rdcp2(IMRPhenomXWaveformStruct *pWF, int RDAmpFlag);
+static double IMRPhenomXHM_RD_Amp_21_rdcp3(IMRPhenomXWaveformStruct *pWF, int RDAmpFlag);
+static double IMRPhenomXHM_RD_Amp_33_rdcp1(IMRPhenomXWaveformStruct *pWF, int RDAmpFlag);
+static double IMRPhenomXHM_RD_Amp_33_rdcp2(IMRPhenomXWaveformStruct *pWF, int RDAmpFlag);
+static double IMRPhenomXHM_RD_Amp_33_rdcp3(IMRPhenomXWaveformStruct *pWF, int RDAmpFlag);
+static double IMRPhenomXHM_RD_Amp_32_rdcp1(IMRPhenomXWaveformStruct *pWF, int RDAmpFlag);
+static double IMRPhenomXHM_RD_Amp_32_rdcp2(IMRPhenomXWaveformStruct *pWF, int RDAmpFlag);
+static double IMRPhenomXHM_RD_Amp_32_rdcp3(IMRPhenomXWaveformStruct *pWF, int RDAmpFlag);
+static double IMRPhenomXHM_RD_Amp_44_rdcp1(IMRPhenomXWaveformStruct *pWF, int RDAmpFlag);
+static double IMRPhenomXHM_RD_Amp_44_rdcp2(IMRPhenomXWaveformStruct *pWF, int RDAmpFlag);
+static double IMRPhenomXHM_RD_Amp_44_rdcp3(IMRPhenomXWaveformStruct *pWF, int RDAmpFlag);
+static double IMRPhenomXHM_RD_Amp_32_rdaux1(IMRPhenomXWaveformStruct *pWF, int RDAmpFlag);
+static double IMRPhenomXHM_RD_Amp_32_rdaux2(IMRPhenomXWaveformStruct *pWF, int RDAmpFlag);
+
+/* End of Amp Parameter Space Fits */
+
+// Ringdown coefficients from collocation points
+static void IMRPhenomXHM_RD_Amp_Coefficients(IMRPhenomXWaveformStruct *pWF22, IMRPhenomXHMWaveformStruct *pWFHM, IMRPhenomXHMAmpCoefficients *pAmp);
+static void IMRPhenomXHM_RDAux_Amp_Coefficients(IMRPhenomXWaveformStruct *pWF22, IMRPhenomXHMWaveformStruct *pWFHM, IMRPhenomXHMAmpCoefficients *pAmp);
+
+//ansatz, and its derivative: analytical for no mixing and numerical for mixing
+static double IMRPhenomXHM_RD_Amp_Ansatz(IMRPhenomX_UsefulPowers *powers_of_Mf, IMRPhenomXHMWaveformStruct *pWF,  IMRPhenomXHMAmpCoefficients *pAmp);
+static double IMRPhenomXHM_RD_Amp_DAnsatz(IMRPhenomX_UsefulPowers *powers_of_Mf, IMRPhenomXHMWaveformStruct *pWF, IMRPhenomXHMAmpCoefficients *pAmp);
+static double IMRPhenomXHM_RD_Amp_NDAnsatz(IMRPhenomX_UsefulPowers *powers_of_Mf, IMRPhenomXHMAmpCoefficients *pAmp,  IMRPhenomXHMPhaseCoefficients *pPhase, IMRPhenomXHMWaveformStruct *pWFHM, IMRPhenomXAmpCoefficients *pAmp22,  IMRPhenomXPhaseCoefficients *pPhase22, IMRPhenomXWaveformStruct *pWF22);
+
+// Feeding the ansatz with the coefficients is how we get the final reconstruction
+
+//veto
+static void IMRPhenomXHM_Ringdown_Amplitude_Veto(double *pV2, double *pV3, double V4, IMRPhenomXHMWaveformStruct *pWFHM, IMRPhenomXWaveformStruct *pWF22);
+
+
+//----PHASE-----
+
+// no mixing fits
+static double IMRPhenomXHM_RD_Phase_22_alpha2(IMRPhenomXWaveformStruct *pWF, int RDPhaseFlag);
+static double IMRPhenomXHM_RD_Phase_22_alphaL(IMRPhenomXWaveformStruct *pWF, int RDPhaseFlag);
+// 32 specific fits
+static double IMRPhenomXHM_RD_Phase_32_SpheroidalTimeShift(IMRPhenomXWaveformStruct *pWF, int RDPhaseFlag);
+static double IMRPhenomXHM_RD_Phase_32_SpheroidalPhaseShift(IMRPhenomXWaveformStruct *pWF, int RDPhaseFlag);
+static double IMRPhenomXHM_RD_Phase_32_p1(IMRPhenomXWaveformStruct *pWF, int RingdownPhaseFlag);
+static double IMRPhenomXHM_RD_Phase_32_p2(IMRPhenomXWaveformStruct *pWF, int RingdownPhaseFlag);
+static double IMRPhenomXHM_RD_Phase_32_p3(IMRPhenomXWaveformStruct *pWF, int RingdownPhaseFlag);
+static double IMRPhenomXHM_RD_Phase_32_p4(IMRPhenomXWaveformStruct *pWF, int RingdownPhaseFlag);
+static double IMRPhenomXHM_RD_Phase_32_p5(IMRPhenomXWaveformStruct *pWF, int RDPhaseFlag);
+static double IMRPhenomXHM_RD_Phase_32_p5(IMRPhenomXWaveformStruct *pWF, int RDPhaseFlag);
+
+/* End of Phase Parameter Space Fits */
+
+//ansatz
+static double IMRPhenomXHM_RD_Phase_Ansatz(double ff,IMRPhenomX_UsefulPowers *powers_of_f, IMRPhenomXHMWaveformStruct *pWFHM,  IMRPhenomXHMPhaseCoefficients *pPhase);
+static double IMRPhenomXHM_RD_Phase_AnsatzInt(double ff, IMRPhenomX_UsefulPowers *powers_of_f,IMRPhenomXHMWaveformStruct *pWFHM,  IMRPhenomXHMPhaseCoefficients *pPhase);
 
 #ifdef __cplusplus
 }
 #endif
 
 
-#endif 
+#endif
diff --git a/lalsimulation/lib/LALSimIMRPhenomXHM_structs.h b/lalsimulation/lib/LALSimIMRPhenomXHM_structs.h
index 0a7f1100ef3ea176cda53e15d990b023191c3704..009d76489510f47f95771e004ec6c513c8888963 100644
--- a/lalsimulation/lib/LALSimIMRPhenomXHM_structs.h
+++ b/lalsimulation/lib/LALSimIMRPhenomXHM_structs.h
@@ -31,17 +31,18 @@ extern "C" {
 
 
 #include <lal/LALAtomicDatatypes.h>
+#include "LALSimIMRPhenomX_internals.h"
 
 #define N_HIGHERMODES_IMPLEMENTED 4 // lm = (21, 33, 32, 44)
 
 #define N_MAX_COEFFICIENTS_PHASE_INS 13       //Maximun number of coefficients of the inspiral ansatz
 #define N_MAX_COEFFICIENTS_PHASE_INTER 6      //Maximun number of coefficients of the intermediate ansatz
-#define N_MAX_COEFFICIENTS_PHASE_RING 4       //Maximun number of coefficients of the ringdown ansatz
+#define N_MAX_COEFFICIENTS_PHASE_RING 8       //Maximun number of coefficients of the ringdown ansatz. 5 + 3 optional for flattened phi'
 
 #define N_MAX_COEFFICIENTS_AMPLITUDE_INS 3    //Maximun number of collocation points in the inspiral
-#define N_MAX_COEFFICIENTS_AMPLITUDE_INTER 4  //Maximun number of collocation points in the intermediate. The fourth is for the EMR
-#define N_MAX_COEFFICIENTS_AMPLITUDE_RING 3   //Maximun number of coefficients in the ringdown. Only 21 has 3, the rest 2.
-
+#define N_MAX_COEFFICIENTS_AMPLITUDE_INTER 8  //Maximun number of collocation points in the intermediate. New release 4 coll points + 2x2 boundaries
+#define N_MAX_COEFFICIENTS_AMPLITUDE_RING 6   //Maximun number of coefficients in the ringdown. We only use 3 degrees of freedom, but we have the double to store fits of 3 coefficients or 3 collocation points 
+#define N_MAX_COEFFICIENTS_AMPLITUDE_RDAUX 4  //Maximun number of coefficients in the ringdown auxiliar region for mode-mixing. Default 2 collocation points + point & derivative right boundary
 
 // Data structure to hold QNM frequencies
 typedef double (*fitQNM_fring) (double finalDimlessSpin);
@@ -54,12 +55,16 @@ typedef struct tagQNMFits {
 
 
 // General fit function. This is a type for defining the functions for the parameter space fits.
-typedef double (*ParameterSpaceFit) (double eta, double S, double chi1, double chi2, int flag);
+typedef double (*ParameterSpaceFit) (IMRPhenomXWaveformStruct *pWF, int flag);
 
 // Waveform struct.  Store useful variable specific of the higher modes that are not in 22 IMRPhenomXWaveformStruct or that need to be updated mode-by-mode. */
 typedef struct tagIMRPhenomXHMWaveformStruct
 {
         /* Model Version Parameters */
+        INT4  IMRPhenomXHMInspiralAmpVersion;
+        INT4  IMRPhenomXHMIntermediateAmpVersion;
+        INT4  IMRPhenomXHMRingdownAmpVersion;
+        
         INT4  IMRPhenomXHMInspiralPhaseVersion;
         INT4  IMRPhenomXHMIntermediatePhaseVersion;
         INT4  IMRPhenomXHMRingdownPhaseVersion;
@@ -68,16 +73,28 @@ typedef struct tagIMRPhenomXHMWaveformStruct
         INT4  IMRPhenomXHMIntermediateAmpFitsVersion;
         INT4  IMRPhenomXHMRingdownAmpFitsVersion;
 
-        INT4  IMRPhenomXHMInspiralAmpVersion;
-        INT4  IMRPhenomXHMIntermediateAmpVersion;
-        INT4  IMRPhenomXHMRingdownAmpVersion;
+        INT4  IMRPhenomXHMInspiralPhaseFitsVersion;
+        INT4  IMRPhenomXHMIntermediatePhaseFitsVersion;
+        INT4  IMRPhenomXHMRingdownPhaseFitsVersion;
+
+        INT4  IMRPhenomXHMInspiralAmpFreqsVersion;
+        INT4  IMRPhenomXHMIntermediateAmpFreqsVersion;
+        INT4  IMRPhenomXHMRingdownAmpFreqsVersion;
+        
+        INT4  IMRPhenomXHMInspiralPhaseFreqsVersion;
+        INT4  IMRPhenomXHMIntermediatePhaseFreqsVersion;
+        INT4  IMRPhenomXHMRingdownPhaseFreqsVersion;
+
+        
+
+        INT4 IMRPhenomXHMReleaseVersion;
 
 
         /* Spin Parameters */
         REAL8 chi_s, chi_a;  // (chi1 +/- chi2)/2
 
         /* MECO, Ringdown and Damping Frequencies */
-				REAL8 fMECOlm;  // = wf22->fMECO*m/2
+		    REAL8 fMECOlm;  // = wf22->fMECO*m/2
         REAL8 fRING;
         REAL8 fDAMP;
 
@@ -126,10 +143,13 @@ typedef struct tagIMRPhenomXHMWaveformStruct
 
         // Variable to control the use of FAmpPN function for 21 instead of the power series
         INT4 useFAmpPN;
-    
+
         /* time-shift of the peak of the hybrids' 22 wrt end of the waveform*/
         REAL8 DeltaT;
 
+        REAL8 fPhaseRDflat;      // Ringdown -> Flattened region
+        REAL8 fAmpRDfalloff;     // Ringdown -> Falloff region
+
     } IMRPhenomXHMWaveformStruct;
 
 
@@ -142,11 +162,17 @@ typedef struct tagIMRPhenomXHMWaveformStruct
             REAL8 fAmpMatchIN;    // Inspiral -> Intermediate
             REAL8 fAmpMatchInt12; // Intermediate1 -> Intermediate2. Only for EMR cases
             REAL8 fAmpMatchIM;    // Intermediate -> Ringdown
+            REAL8 fRDAux;  // Auxiliar Ringdown region for mode-mixing
 
             /* PN Amplitude Prefactors */
             COMPLEX16 pnInitial, pnOneThird, pnTwoThirds, pnThreeThirds, pnFourThirds, pnFiveThirds, pnSixThirds, pnSevenThirds, pnEightThirds,pnNineThirds;
 
-            /* PN Amplitude global prefactor */
+            /* PN Amplitude dominant factor = Pi * Sqrt(2 eta/3) (2Pi /m)^(-7/6) */
+            REAL8 PNdominant, PNdominantlm, ampNorm;
+
+            UINT2 PNdominantlmpower;
+
+            /* PN Amplitude global prefactor = leading lm order after substracting PNdominant*/
             REAL8 PNglobalfactor;
 
             /* Coefficients of the pseudo-PN terms */
@@ -158,21 +184,31 @@ typedef struct tagIMRPhenomXHMWaveformStruct
             /* Coefficients of the polynomial in the first intermediate region (for EMR only). 4th order.*/
             REAL8 alpha0, alpha1, alpha2, alpha3, alpha4;
 
-            /* Coefficients of the Ringdown ansatz */
-            REAL8 alambda, lambda, sigma, lc;
-
             // fits of coefficients/collocation points
             ParameterSpaceFit InspiralAmpFits[N_HIGHERMODES_IMPLEMENTED*N_MAX_COEFFICIENTS_AMPLITUDE_INS];
             ParameterSpaceFit IntermediateAmpFits[N_HIGHERMODES_IMPLEMENTED*N_MAX_COEFFICIENTS_AMPLITUDE_INTER];
-            ParameterSpaceFit RingdownAmpFits[N_HIGHERMODES_IMPLEMENTED*N_MAX_COEFFICIENTS_AMPLITUDE_RING];
+            ParameterSpaceFit RingdownAmpFits[N_HIGHERMODES_IMPLEMENTED*N_MAX_COEFFICIENTS_AMPLITUDE_RING + N_MAX_COEFFICIENTS_AMPLITUDE_RDAUX];
 
             /* Flag to set how many collocation points the inspiral region uses  */
             REAL8 CollocationPointsValuesAmplitudeInsp[N_MAX_COEFFICIENTS_AMPLITUDE_INS];
             REAL8 CollocationPointsFreqsAmplitudeInsp[N_MAX_COEFFICIENTS_AMPLITUDE_INS];
+            REAL8 InspiralCoefficient[N_MAX_COEFFICIENTS_AMPLITUDE_INS];
 
             /* Flag to set how many collocation points the intermediate region uses */
             REAL8 CollocationPointsFreqsAmplitudeInter[N_MAX_COEFFICIENTS_AMPLITUDE_INTER];
             REAL8 CollocationPointsValuesAmplitudeInter[N_MAX_COEFFICIENTS_AMPLITUDE_INTER];
+            REAL8 InterCoefficient[N_MAX_COEFFICIENTS_AMPLITUDE_INTER];
+            UINT2 nCoefficientsInter;
+            UINT2 VersionCollocPtsInter[N_MAX_COEFFICIENTS_AMPLITUDE_INTER];
+
+            /* Flag to set how many collocation points the intermediate region uses */
+            REAL8 CollocationPointsFreqsAmplitudeRD[N_MAX_COEFFICIENTS_AMPLITUDE_RING];
+            REAL8 CollocationPointsValuesAmplitudeRD[N_MAX_COEFFICIENTS_AMPLITUDE_RING];
+            REAL8 RDCoefficient[N_MAX_COEFFICIENTS_AMPLITUDE_RING];
+            REAL8 CollocationPointsFreqsAmplitudeRDAux[N_MAX_COEFFICIENTS_AMPLITUDE_RDAUX];
+            REAL8 CollocationPointsValuesAmplitudeRDAux[N_MAX_COEFFICIENTS_AMPLITUDE_RDAUX];
+            REAL8 RDAuxCoefficient[N_MAX_COEFFICIENTS_AMPLITUDE_RDAUX];
+            UINT2 nCollocPtsRDAux, nCoefficientsRDAux;
 
             // Frequencies, values and derivatives for the intermediate reconstruction
             // The frequencies are the same than in CollocationPointsFreqsAmplitudeInsp for the corresponding mode,
@@ -182,8 +218,8 @@ typedef struct tagIMRPhenomXHMWaveformStruct
             // Order of the polynomial in the intermediate region. 5th->105, for the first EMR region is 1042
             INT4 InterAmpPolOrder;
 
-    				// Store the PN amplitude at the frequencies of the collocation points in the inspiral
-    				REAL8 PNAmplitudeInsp[N_MAX_COEFFICIENTS_AMPLITUDE_INS];
+        		// Store the PN amplitude at the frequencies of the collocation points in the inspiral
+        		REAL8 PNAmplitudeInsp[N_MAX_COEFFICIENTS_AMPLITUDE_INS];
 
             // For the pseudo part of Inspiral Amplitude ansatz. Used in LALSimIMRPhenomXHM_inspiral.c
             REAL8 fcutInsp_seven_thirds;
@@ -201,9 +237,11 @@ typedef struct tagIMRPhenomXHMWaveformStruct
             // Variables to control if we have to check that the collocation points are wavy
             INT4 WavyInsp, WavyInt;
 
-            // Amp0 = wf22->ampNorm * wf22->amp0. Multiplying by this gives the amp factor of the 22 and transform to "physical" units
+            // Amp0 = wf22->ampNorm * wf22->amp0. Multiplying by this gives the amp factor of the 22 and transforms to "physical" units
             REAL8 Amp0;
 
+            UINT2 InspRescaleFactor, InterRescaleFactor, RDRescaleFactor;
+
     } IMRPhenomXHMAmpCoefficients;
 
 
@@ -215,9 +253,9 @@ typedef struct tagIMRPhenomXHMPhaseCoefficients
         /* Phase Transition Frequencies */
         REAL8 fPhaseMatchIN;
         REAL8 fPhaseMatchIM;
-    
+
         REAL8 deltaphiLM;
-         
+
         /* These are the RD phenomenological coefficients, with mode-mixing off */
         REAL8 alpha0, alpha2, alphaL;
         REAL8 phi0RD, dphi0RD;
@@ -243,6 +281,7 @@ typedef struct tagIMRPhenomXHMPhaseCoefficients
         INT4  NCollocationPointsRD;
         REAL8 CollocationPointsValuesPhaseRD[N_MAX_COEFFICIENTS_PHASE_RING];
         REAL8 CollocationPointsFreqsPhaseRD[N_MAX_COEFFICIENTS_PHASE_RING];
+        REAL8 RDCoefficient[N_MAX_COEFFICIENTS_PHASE_RING + 3]; // Add the three coefficient for rational decay
 
         /* Flag to set how many collocation points the intermediate region uses */
         INT4  NCollocationPointsInt;
diff --git a/lalsimulation/lib/LALSimIMRPhenomXPHM.c b/lalsimulation/lib/LALSimIMRPhenomXPHM.c
index 41028373e2cfeb2109aa595b7e8175e0d5224066..f02365cd0796f8773536f9de35f50cef76bfd3a7 100644
--- a/lalsimulation/lib/LALSimIMRPhenomXPHM.c
+++ b/lalsimulation/lib/LALSimIMRPhenomXPHM.c
@@ -2951,8 +2951,7 @@ INT4 XLALSimIMRPhenomXPHMMultibandingGrid(
    printf("fDAMP = %e\n",pWFHM->fDAMP);
    printf("alphaL = %.16e", pPhase->alphaL);
    #endif
-   dfmerger = deltaF_mergerBin(pWFHM->fDAMP, pPhase->alphaL, thresholdMB);
-   dfringdown = deltaF_ringdownBin(pWFHM->fDAMP, pPhase->alphaL, pAmp->lambda/(pAmp->sigma*pWFHM->fDAMP), thresholdMB);
+   deltaF_MergerRingdown(&dfmerger, &dfringdown, thresholdMB, pWFHM, pAmp, pPhase);
  }
  LALFree(pWFHM);
  LALFree(pAmp);
diff --git a/lalsimulation/lib/LALSimIMRPhenomX_internals.c b/lalsimulation/lib/LALSimIMRPhenomX_internals.c
index 6eef492f24a083113df636c3c608100f772663f3..262f8dcad222988fdb78fcc5665a080d856f44a0 100644
--- a/lalsimulation/lib/LALSimIMRPhenomX_internals.c
+++ b/lalsimulation/lib/LALSimIMRPhenomX_internals.c
@@ -89,6 +89,7 @@ int IMRPhenomX_Initialize_Powers(IMRPhenomX_UsefulPowers *p, REAL8 number)
 	p->m_two          = 1.0 / p->two;
 	p->m_three        = 1.0 / p->three;
 	p->m_four         = 1.0 / p->four;
+	p->m_five         = 1.0 / p->five;
 
 	p->seven_sixths   = p->one_sixth   * p->itself;
 	p->m_seven_sixths = p->m_one_sixth * p->m_one;
@@ -418,6 +419,7 @@ int IMRPhenomXSetWaveformVariables(
 	wf->chiPNHat  = XLALSimIMRPhenomXchiPNHat(eta,chi1L,chi2L);
 	wf->STotR     = XLALSimIMRPhenomXSTotR(eta,chi1L,chi2L);
 	wf->dchi      = XLALSimIMRPhenomXdchi(chi1L,chi2L);
+	wf->dchi_half = wf->dchi*0.5;
 
 	wf->SigmaL    = (wf->chi2L * wf->m2) - (wf->chi1L * wf->m1); 										// SigmaL = (M/m2)*(S2.L) - (M/m2)*(S1.L)
 	wf->SL        = wf->chi1L * (wf->m1 * wf->m1) + wf->chi2L * (wf->m2 * wf->m2);  // SL = S1.L + S2.L
diff --git a/lalsimulation/lib/LALSimIMRPhenomX_internals.h b/lalsimulation/lib/LALSimIMRPhenomX_internals.h
index a0d4895e83f3660b02a1bd33848586403abf8895..1ffe437773601a0608c8482571c7805f9d7a5668 100644
--- a/lalsimulation/lib/LALSimIMRPhenomX_internals.h
+++ b/lalsimulation/lib/LALSimIMRPhenomX_internals.h
@@ -98,6 +98,7 @@ typedef struct tagIMRPhenomXWaveformStruct
 	REAL8 chiPNHat;
 	REAL8 STotR;
 	REAL8 dchi;
+	REAL8 dchi_half;
 	REAL8 SL;
 	REAL8 SigmaL;
 
diff --git a/lalsimulation/lib/LALSimInspiralWaveformParams.c b/lalsimulation/lib/LALSimInspiralWaveformParams.c
index 35e431f01b9f1744a1eb2b00d415e4b2a4acdec1..f3b03c876cc60d7d046773a5dda21871f5474720 100644
--- a/lalsimulation/lib/LALSimInspiralWaveformParams.c
+++ b/lalsimulation/lib/LALSimInspiralWaveformParams.c
@@ -194,6 +194,7 @@ DEFINE_INSERT_FUNC(PhenomXPFinalSpinMod, INT4, "FinalSpinMod", 4)
 DEFINE_INSERT_FUNC(PhenomXPTransPrecessionMethod, INT4, "TransPrecessionMethod", 1)
 
 /* IMRPhenomXHM Parameters */
+DEFINE_INSERT_FUNC(PhenomXHMReleaseVersion, INT4, "PhenomXHMReleaseVersion", 122022)
 DEFINE_INSERT_FUNC(PhenomXHMInspiralPhaseVersion, INT4, "InsPhaseHMVersion", 122019)
 DEFINE_INSERT_FUNC(PhenomXHMIntermediatePhaseVersion, INT4, "IntPhaseHMVersion", 122019)
 DEFINE_INSERT_FUNC(PhenomXHMRingdownPhaseVersion, INT4, "RDPhaseHMVersion", 122019)
@@ -203,6 +204,9 @@ DEFINE_INSERT_FUNC(PhenomXHMRingdownAmpVersion, INT4, "RDAmpHMVersion", 0)
 DEFINE_INSERT_FUNC(PhenomXHMInspiralAmpFitsVersion, INT4, "InsAmpFitsVersion", 122018)
 DEFINE_INSERT_FUNC(PhenomXHMIntermediateAmpFitsVersion, INT4, "IntAmpFitsVersion", 122018)
 DEFINE_INSERT_FUNC(PhenomXHMRingdownAmpFitsVersion, INT4, "RDAmpFitsVersion", 122018)
+DEFINE_INSERT_FUNC(PhenomXHMInspiralAmpFreqsVersion, INT4, "InsAmpFreqsVersion", 122018)
+DEFINE_INSERT_FUNC(PhenomXHMIntermediateAmpFreqsVersion, INT4, "IntAmpFreqsVersion", 122018)
+DEFINE_INSERT_FUNC(PhenomXHMRingdownAmpFreqsVersion, INT4, "RDAmpFreqsVersion", 122018)
 DEFINE_INSERT_FUNC(PhenomXHMPhaseRef21, REAL8, "PhaseRef21", 0.)
 DEFINE_INSERT_FUNC(PhenomXHMThresholdMband, REAL8, "ThresholdMband", 0.001)
 DEFINE_INSERT_FUNC(PhenomXHMAmpInterpolMB, INT4, "AmpInterpol", 1)
@@ -375,6 +379,7 @@ DEFINE_LOOKUP_FUNC(PhenomXPFinalSpinMod, INT4, "FinalSpinMod", 4)
 DEFINE_LOOKUP_FUNC(PhenomXPTransPrecessionMethod, INT4, "TransPrecessionMethod", 1)
 
 /* IMRPhenomXHM Parameters */
+DEFINE_LOOKUP_FUNC(PhenomXHMReleaseVersion, INT4, "PhenomXHMReleaseVersion", 122022)
 DEFINE_LOOKUP_FUNC(PhenomXHMInspiralPhaseVersion, INT4, "InsPhaseHMVersion", 122019)
 DEFINE_LOOKUP_FUNC(PhenomXHMIntermediatePhaseVersion, INT4, "IntPhaseHMVersion", 122019)
 DEFINE_LOOKUP_FUNC(PhenomXHMRingdownPhaseVersion, INT4, "RDPhaseHMVersion", 122019)
@@ -384,6 +389,9 @@ DEFINE_LOOKUP_FUNC(PhenomXHMRingdownAmpVersion, INT4, "RDAmpHMVersion", 0)
 DEFINE_LOOKUP_FUNC(PhenomXHMInspiralAmpFitsVersion, INT4, "InsAmpFitsVersion", 122018)
 DEFINE_LOOKUP_FUNC(PhenomXHMIntermediateAmpFitsVersion, INT4, "IntAmpFitsVersion", 122018)
 DEFINE_LOOKUP_FUNC(PhenomXHMRingdownAmpFitsVersion, INT4, "RDAmpFitsVersion", 122018)
+DEFINE_LOOKUP_FUNC(PhenomXHMInspiralAmpFreqsVersion, INT4, "InsAmpFreqsVersion", 122018)
+DEFINE_LOOKUP_FUNC(PhenomXHMIntermediateAmpFreqsVersion, INT4, "IntAmpFreqsVersion", 122018)
+DEFINE_LOOKUP_FUNC(PhenomXHMRingdownAmpFreqsVersion, INT4, "RDAmpFreqsVersion", 122018)
 DEFINE_LOOKUP_FUNC(PhenomXHMPhaseRef21, REAL8, "PhaseRef21", 0.)
 DEFINE_LOOKUP_FUNC(PhenomXHMThresholdMband, REAL8, "ThresholdMband", 0.001)
 DEFINE_LOOKUP_FUNC(PhenomXHMAmpInterpolMB, INT4, "AmpInterpol", 1)
@@ -530,6 +538,7 @@ DEFINE_ISDEFAULT_FUNC(PhenomXPFinalSpinMod, INT4, "FinalSpinMod", 4)
 DEFINE_ISDEFAULT_FUNC(PhenomXPTransPrecessionMethod, INT4, "TransPrecessionMethod", 1)
 
 /* IMRPhenomXHM Parameters */
+DEFINE_ISDEFAULT_FUNC(PhenomXHMReleaseVersion, INT4, "PhenomXHMReleaseVersion", 122022)
 DEFINE_ISDEFAULT_FUNC(PhenomXHMInspiralPhaseVersion, INT4, "InsPhaseHMVersion", 122019)
 DEFINE_ISDEFAULT_FUNC(PhenomXHMIntermediatePhaseVersion, INT4, "IntPhaseHMVersion", 122019)
 DEFINE_ISDEFAULT_FUNC(PhenomXHMRingdownPhaseVersion, INT4, "RDPhaseHMVersion", 122019)
@@ -539,6 +548,9 @@ DEFINE_ISDEFAULT_FUNC(PhenomXHMRingdownAmpVersion, INT4, "RDAmpHMVersion", 0)
 DEFINE_ISDEFAULT_FUNC(PhenomXHMInspiralAmpFitsVersion, INT4, "InsAmpFitsVersion", 122018)
 DEFINE_ISDEFAULT_FUNC(PhenomXHMIntermediateAmpFitsVersion, INT4, "IntAmpFitsVersion", 122018)
 DEFINE_ISDEFAULT_FUNC(PhenomXHMRingdownAmpFitsVersion, INT4, "RDAmpFitsVersion", 122018)
+DEFINE_ISDEFAULT_FUNC(PhenomXHMInspiralAmpFreqsVersion, INT4, "InsAmpFreqsVersion", 122018)
+DEFINE_ISDEFAULT_FUNC(PhenomXHMIntermediateAmpFreqsVersion, INT4, "IntAmpFreqsVersion", 122018)
+DEFINE_ISDEFAULT_FUNC(PhenomXHMRingdownAmpFreqsVersion, INT4, "RDAmpFreqsVersion", 122018)
 DEFINE_ISDEFAULT_FUNC(PhenomXHMPhaseRef21, REAL8, "PhaseRef21", 0.)
 DEFINE_ISDEFAULT_FUNC(PhenomXHMThresholdMband, REAL8, "ThresholdMband", 0.001)
 DEFINE_ISDEFAULT_FUNC(PhenomXHMAmpInterpolMB, INT4, "AmpInterpol", 1)
diff --git a/lalsimulation/lib/LALSimInspiralWaveformParams.h b/lalsimulation/lib/LALSimInspiralWaveformParams.h
index 4fa2b6cab4c471e07ee4c4a0bd3117eb67f56a5b..916ab01ece255d18ffc49f8559e327f8b88131e0 100644
--- a/lalsimulation/lib/LALSimInspiralWaveformParams.h
+++ b/lalsimulation/lib/LALSimInspiralWaveformParams.h
@@ -59,6 +59,7 @@ int XLALSimInspiralWaveformParamsInsertPhenomXPFinalSpinMod(LALDict *params, INT
 int XLALSimInspiralWaveformParamsInsertPhenomXPTransPrecessionMethod(LALDict *params, INT4 value);
 
 /* IMRPhenomXHM Parameters */
+int XLALSimInspiralWaveformParamsInsertPhenomXHMReleaseVersion(LALDict *params, INT4 value);
 int XLALSimInspiralWaveformParamsInsertPhenomXHMInspiralPhaseVersion(LALDict *params, INT4 value);
 int XLALSimInspiralWaveformParamsInsertPhenomXHMIntermediatePhaseVersion(LALDict *params, INT4 value);
 int XLALSimInspiralWaveformParamsInsertPhenomXHMRingdownPhaseVersion(LALDict *params, INT4 value);
@@ -68,6 +69,9 @@ int XLALSimInspiralWaveformParamsInsertPhenomXHMRingdownAmpVersion(LALDict *para
 int XLALSimInspiralWaveformParamsInsertPhenomXHMInspiralAmpFitsVersion(LALDict *params, INT4 value);
 int XLALSimInspiralWaveformParamsInsertPhenomXHMIntermediateAmpFitsVersion(LALDict *params, INT4 value);
 int XLALSimInspiralWaveformParamsInsertPhenomXHMRingdownAmpFitsVersion(LALDict *params, INT4 value);
+int XLALSimInspiralWaveformParamsInsertPhenomXHMInspiralAmpFreqsVersion(LALDict *params, INT4 value);
+int XLALSimInspiralWaveformParamsInsertPhenomXHMIntermediateAmpFreqsVersion(LALDict *params, INT4 value);
+int XLALSimInspiralWaveformParamsInsertPhenomXHMRingdownAmpFreqsVersion(LALDict *params, INT4 value);
 int XLALSimInspiralWaveformParamsInsertPhenomXHMPhaseRef21(LALDict *params, REAL8 value);
 int XLALSimInspiralWaveformParamsInsertPhenomXHMThresholdMband(LALDict *params, REAL8 value);
 int XLALSimInspiralWaveformParamsInsertPhenomXHMAmpInterpolMB(LALDict *params, INT4 value);
@@ -215,6 +219,7 @@ INT4 XLALSimInspiralWaveformParamsLookupPhenomXPConvention(LALDict *params);
 INT4 XLALSimInspiralWaveformParamsLookupPhenomXPFinalSpinMod(LALDict *params);
 
 /* IMRPhenomXHM Parameters */
+INT4 XLALSimInspiralWaveformParamsLookupPhenomXHMReleaseVersion(LALDict *params);
 INT4 XLALSimInspiralWaveformParamsLookupPhenomXHMInspiralPhaseVersion(LALDict *params);
 INT4 XLALSimInspiralWaveformParamsLookupPhenomXHMIntermediatePhaseVersion(LALDict *params);
 INT4 XLALSimInspiralWaveformParamsLookupPhenomXHMRingdownPhaseVersion(LALDict *params);
@@ -224,6 +229,9 @@ INT4 XLALSimInspiralWaveformParamsLookupPhenomXHMRingdownAmpVersion(LALDict *par
 INT4 XLALSimInspiralWaveformParamsLookupPhenomXHMInspiralAmpFitsVersion(LALDict *params);
 INT4 XLALSimInspiralWaveformParamsLookupPhenomXHMIntermediateAmpFitsVersion(LALDict *params);
 INT4 XLALSimInspiralWaveformParamsLookupPhenomXHMRingdownAmpFitsVersion(LALDict *params);
+INT4 XLALSimInspiralWaveformParamsLookupPhenomXHMInspiralAmpFreqsVersion(LALDict *params);
+INT4 XLALSimInspiralWaveformParamsLookupPhenomXHMIntermediateAmpFreqsVersion(LALDict *params);
+INT4 XLALSimInspiralWaveformParamsLookupPhenomXHMRingdownAmpFreqsVersion(LALDict *params);
 REAL8 XLALSimInspiralWaveformParamsLookupPhenomXHMPhaseRef21(LALDict *params);
 REAL8 XLALSimInspiralWaveformParamsLookupPhenomXHMThresholdMband(LALDict *params);
 INT4 XLALSimInspiralWaveformParamsLookupPhenomXHMAmpInterpolMB(LALDict *params);
@@ -370,6 +378,7 @@ int XLALSimInspiralWaveformParamsPhenomXPFinalSpinModIsDefault(LALDict *params);
 int XLALSimInspiralWaveformParamsPhenomXPTransPrecessionMethodIsDefault(LALDict *params);
 
 /* IMRPhenomXHM Parameters */
+int XLALSimInspiralWaveformParamsPhenomXHMReleaseVersionIsDefault(LALDict *params);
 int XLALSimInspiralWaveformParamsPhenomXHMInspiralPhaseVersionIsDefault(LALDict *params);
 int XLALSimInspiralWaveformParamsPhenomXHMIntermediatePhaseVersionIsDefault(LALDict *params);
 int XLALSimInspiralWaveformParamsPhenomXHMRingdownPhaseVersionIsDefault(LALDict *params);
@@ -379,6 +388,9 @@ int XLALSimInspiralWaveformParamsPhenomXHMRingdownAmpVersionIsDefault(LALDict *p
 int XLALSimInspiralWaveformParamsPhenomXHMInspiralAmpFitsVersionIsDefault(LALDict *params);
 int XLALSimInspiralWaveformParamsPhenomXHMIntermediateAmpFitsVersionIsDefault(LALDict *params);
 int XLALSimInspiralWaveformParamsPhenomXHMRingdownAmpFitsVersionIsDefault(LALDict *params);
+int XLALSimInspiralWaveformParamsPhenomXHMInspiralAmpFreqsVersionIsDefault(LALDict *params);
+int XLALSimInspiralWaveformParamsPhenomXHMIntermediateAmpFreqsVersionIsDefault(LALDict *params);
+int XLALSimInspiralWaveformParamsPhenomXHMRingdownAmpFreqsVersionIsDefault(LALDict *params);
 int XLALSimInspiralWaveformParamsPhenomXHMPhaseRef21IsDefault(LALDict *params);
 int XLALSimInspiralWaveformParamsPhenomXHMThresholdMbandIsDefault(LALDict *params);
 int XLALSimInspiralWaveformParamsPhenomXHMAmpInterpolMBIsDefault(LALDict *params);
diff --git a/lalsimulation/test/GenerateSimulation.c b/lalsimulation/test/GenerateSimulation.c
index c5ce1ebaa7ce90f39bbf64c364a803f284ad8367..5bacdd9c6fd3435e1e25a64ac43c32f25a65b9e3 100644
--- a/lalsimulation/test/GenerateSimulation.c
+++ b/lalsimulation/test/GenerateSimulation.c
@@ -408,6 +408,8 @@ static GSParams *parse_args(ssize_t argc, char **argv) {
             XLALSimInspiralWaveformParamsInsertPhenomXPrecVersion(params->params, atoi(argv[++i]));
         }else if(strcmp(argv[i], "--phenomXPFinalSpinMod") == 0){
             XLALSimInspiralWaveformParamsInsertPhenomXPFinalSpinMod(params->params, atoi(argv[++i]));
+        }else if(strcmp(argv[i], "--phenomXHMRelease") == 0){
+            XLALSimInspiralWaveformParamsInsertPhenomXHMReleaseVersion(params->params, atoi(argv[++i]));
         }else {
             XLALPrintError("Error: invalid option: %s\n", argv[i]);
             goto fail;
diff --git a/lalsimulation/test/python/test_phenomX.py b/lalsimulation/test/python/test_phenomX.py
index 208c5c7a1893a1dca7c3ef30c42213c3bb66b63f..07ca421684b6ed100ecababc307af7e5c7434c9b 100644
--- a/lalsimulation/test/python/test_phenomX.py
+++ b/lalsimulation/test/python/test_phenomX.py
@@ -34,7 +34,7 @@ def get_amp_phase(h):
 def sum_sqr_diff(x, y):
     return np.sqrt( np.sum( (x-y)**2 )  )
 
-def gen_test_data(spin1x, approximant, mode_array):
+def gen_test_data(spin1x, approximant, mode_array, release=None):
     """
     compute the difference between two waveforms
     and compare to expected value
@@ -47,6 +47,9 @@ def gen_test_data(spin1x, approximant, mode_array):
             lalsimulation.SimInspiralModeArrayActivateMode(ModeArray, mode[0], mode[1])
         lalsimulation.SimInspiralWaveformParamsInsertModeArray(lalparams, ModeArray)
 
+    if release is not None:
+        lalsimulation.SimInspiralWaveformParamsInsertPhenomXHMReleaseVersion(lalparams, release)
+
     common_pars=dict(
     m1=50*lal.MSUN_SI,
     m2=30*lal.MSUN_SI,
@@ -131,18 +134,30 @@ def test_IMRPhenomXHM():
 
     expected_result = np.array([1005.16009183, 169.88197475, 768.18401876, 169.12711241])
 
+    new_result  =  np.array(gen_test_data(0., lalsimulation.IMRPhenomXHM, [[2,2],[2,-2],[2,1],[2,-1],[3,3],[3,-3],[4,4],[4,-4]], release=122019))
+
+    np.testing.assert_allclose(new_result, expected_result, rtol=1e-6, err_msg="IMRPhenomXHM (122019) no 32 mode test failed")
+
+    expected_result = np.array([ 32.17818789, 216.01992794,   4.02227349, 215.97103911])
+
+    new_result  =  np.array(gen_test_data(0., lalsimulation.IMRPhenomXHM, [[3,2],[3,-2]], release=122019))
+
+    # rtol with 32 mode needs to b more lenient
+    np.testing.assert_allclose(new_result, expected_result, rtol=3e-4, err_msg="IMRPhenomXHM (122019) 32 mode test failed")
+
+    expected_result = np.array([1005.01319319, 169.88945372, 768.34648494, 169.13261004])
+
     new_result  =  np.array(gen_test_data(0., lalsimulation.IMRPhenomXHM, [[2,2],[2,-2],[2,1],[2,-1],[3,3],[3,-3],[4,4],[4,-4]]))
 
     np.testing.assert_allclose(new_result, expected_result, rtol=1e-6, err_msg="IMRPhenomXHM no 32 mode test failed")
 
-    expected_result = np.array([ 32.17818789, 216.01992794,   4.02227349, 215.97103911])
+    expected_result = np.array([34.62153262, 218.09073730, 4.32769157, 218.09073730])
 
     new_result  =  np.array(gen_test_data(0., lalsimulation.IMRPhenomXHM, [[3,2],[3,-2]]))
 
     # rtol with 32 mode needs to b more lenient
     np.testing.assert_allclose(new_result, expected_result, rtol=3.1e-4, err_msg="IMRPhenomXHM 32 mode test failed")
 
-
 def test_IMRPhenomXP():
     """
     This test checks that IMRPhenomXP hasn't changed.
@@ -178,14 +193,28 @@ def test_IMRPhenomXPHM():
 
     expected_result = np.array([1166.01091848, 334.5693217,  767.82099062, 326.09652364])
 
-    new_result  =  np.array(gen_test_data(0.5, lalsimulation.IMRPhenomXPHM, [[2,2],[2,1],[3,3],[4,4]]))
+    new_result  =  np.array(gen_test_data(0.5, lalsimulation.IMRPhenomXPHM, [[2,2],[2,1],[3,3],[4,4]], release=122019))
 
     # rtol here needs to be more lenient to pass on builds with arm64 or MKL
-    np.testing.assert_allclose(new_result, expected_result, rtol=1e-5, err_msg="IMRPhenomXPHM no 32 mode test failed")
+    np.testing.assert_allclose(new_result, expected_result, rtol=1e-5, err_msg="IMRPhenomXPHM (122019) no 32 mode test failed")
 
 
     expected_result = np.array([68.9282789725476, 240.20999880535206, 25.111569754767224, 234.7465084316962])
 
+    new_result  =  np.array(gen_test_data(0.5, lalsimulation.IMRPhenomXPHM, [[3,2]], release=122019))
+
+    # rtol with 32 mode needs to b more lenient
+    np.testing.assert_allclose(new_result, expected_result, rtol=3e-4, err_msg="IMRPhenomXPHM (122019) 32 mode test failed")
+
+    expected_result = np.array([1166.77270896, 334.86014307, 768.93672645, 326.38518250])
+
+    new_result  =  np.array(gen_test_data(0.5, lalsimulation.IMRPhenomXPHM, [[2,2],[2,1],[3,3],[4,4]]))
+
+    # rtol here needs to be more lenient to pass on builds with arm64 or MKL
+    np.testing.assert_allclose(new_result, expected_result, rtol=1e-5, err_msg="IMRPhenomXPHM no 32 mode test failed")
+
+    expected_result = np.array([71.43504434, 242.82287296, 26.54528442, 237.35077401])
+
     new_result  =  np.array(gen_test_data(0.5, lalsimulation.IMRPhenomXPHM, [[3,2]]))
 
     # rtol with 32 mode needs to b more lenient