Reordered cgp.c to match documentation (incomplete)