         }
 
         // 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 meas_i[c_m]
+        double meas_unc_i[c_m]
+        for (int k=0; k<c_m; k++) {
+            // grab the measurements for this data point
+            meas_i[k] = meas[n * k + i];
+            meas_unc_i[k] = meas_unc[n * k + i];
+        }
+        
+        logdens_meas = logdensity_meas(meas_i, meas_unc_i, new_chi);
+        logdens_pop = logdensity_pop(new_chi, c_theta);
         double logdens_prop = logdens_meas + logdens_pop;
         
         // Compute the Metropolis ratio

    temperature = exp(chi[2]);
    
    double logdensity = 0.0
    for (int k=0; k<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;

        
        if (unif_draw < ratio) {
            // Accept this proposal, so save this parameter value and conditional log-posterior
            for (int j=0; j<c_p; j++) {
                chi[n * j + i] = new_chi[j];
            }
            logdens[i] = logdens_pop;
        }

        // Copy state back to global memory
        state[i] = localState;

        // Finally, adapt the Cholesky factor of the proposal distribution
        // TODO: check that the ratio is finite before doing this step
        double decay_sequence = 1.0 / pow(current_iter, c_decay_rate);
        
	}
}

