Fixed bugs in code generation