Moved const updating to a function, fixed pair generation.
Changed cg functions to be more readable.
Changed isinstance to is_something functions already defined.