Some important fixes, particularly to calc_C

Avoid bad return from calc_C for large values of p_gamma, plus fix some
other issues with new implementation and add check that
log_X_not_included really is a matrix t