Refactored codebase.

Should now be easier to generate libraries in other languages.

The libraries it generates are now created in a less hacky way.