Works with all official examples.

It's a bit messy, but well commented, and gone through fairly thoroughly at the mechanical level.