More codegen refactoring with simonpj