Fix a number of bugs in generated code.