More codegen refactors