Mostly working codegen