Refactors cg and reenables cg tests