alternative code generation strategy

Tries to put generated code at the end of the file as much as possible.