     temperature = exp(chi[2]);
     
     double logdensity = 0.0
-    for (int k=0; k<m; k++) {
+    for (int k=0; k<c_m; k++) {
         model_sed = modified_bbody(c_nu[k], normalization, beta, temperature);
         double stnd_meas = (meas[k] - model_sed) / meas_unc[k]
         logdensity += -0.5 * stnd_meas * stnd_meas;

        }

        // Compute the conditional log-posterior of the proposed parameter values for this data point
        double centered_meas = meas_i - new_chi;
        double logdens_meas = -0.5 * centered_meas * centered_meas / (meas_unc_i * meas_unc_i);
        double centered_chi = new_chi - mu;
        double logdens_pop = -0.5 * log(var) - 0.5 * centered_chi * centered_chi / var;
        double logdens_prop = logdens_meas + logdens_pop;
        
        // Compute the Metropolis ratio

        // Copy variables to local memory for efficiency
        curandState localState = state[i];
        dim_cholfactor = c_p * c_p - ((c_p - 1) * c_p) / 2;  // cholesky factor is a lower-diagonal matrix
        double cholfactor[dim_cholfactor];
        for (int j=0; j<dim_cholfactor; j++) {
            cholfactor[j] = prop_cholfact[n * j + i];
        }

        // get the unit proposal
        double snorm_deviate[c_p];
        for (int j=0; j<c_p; j++) {
            snorm_deviate[j] = curand_normal_double(&localState);
        }
        
        // propose a new chi value
        double new_chi[c_p];
        cholfact_index = 0
        for (int j=0; j<c_p; j++) {
            double centered_proposal = 0.0;
