Latest spike of the refactor of the code generation; almost done refactoing it so I can look at the C++ code shortly...