Codegen enhancements and fixes