This seems to compile. Needs cleaning up if it actually works.