At least it compiles and passes a sanity test. Needs more testing.