fixed some code generation bugs