Compiled but untested.

Pretty sure there's glaring errors in here.  I have a workaround for
the most obvious one and thoughts on how to do some of the other
missing functions.