Some codegen fixes and cleanup