Finish up fixing the code generation and tidy up the source files.
Fixes #36