fixed some bugs in Code generation