         double* p_prop_cholfact = thrust::raw_pointer_cast(&d_prop_cholfact[0]);
         double* p_logdens = thrust::raw_pointer_cast(&d_logdens[0]);
         int current_iter = i + 1;
-        update_chi<<<nBlocks,nThreads>>>(p_chi, p_meas, p_meas_unc, n, p_logdens, p_prop_cholfact, devStates, current_iter);
+        update_chi<<<nBlocks,nThreads>>>(p_chi, p_meas, p_meas_unc, ndata, p_logdens, p_prop_cholfact, devStates, current_iter);
 
         // Generate new theta in parallel with GPU calculation above
         thrust::host_vector<double> proposed_theta(dim_theta);

    thrust::device_vector<double> d_meas_unc = h_meas_unc;
    thrust::device_vector<double> d_chi = h_chi;
    thrust::device_vector<double> d_prop_cholfact = h_prop_cholfact;
    thrust::device_vector<double> d_logdens(n);  // log posteriors for an individual data point

    thrust::fill(d_logdens.begin(), d_logdens.end(), -1.0e300);


            double proposed_var_j = exp(proposed_theta[j + p]);
            // transform and reduction is over d_chi[j * n : (j+1) * n - 1]
            zsqr zsqrj(proposed_mu_j, proposed_var_j);
            logdens_pop = thrust::transform_reduce(chi_iter_begin, chi_iter_begin+ndata,
                                                zsqrj, logdens_pop, thrust::plus<double>());
            thrust::advance(chi_iter_begin, ndata);
        }

        double logdens_old = thrust::reduce(d_logdens.begin(), d_logdens.end());
