Fix some codegen bugs