Fix some code generation bugs