Fix bugs in CodeGen methods