Fix for cg() and add a test