Add better error checking to cpg.