fix bugs in codegen.C