Still need to clean this up, basic code generation (sort of) working.