CodeGen improvements

I've made GenCode modular, just a cosmetic and maintenance thing.

See CRM-13871