Big refactoring. This is a WIP.

Lots of stuff is now broken. The library will become more middleware like
and extendible.

Please don't use.