Code cleanup and doogfooding

The last pieces of code were pushed in a hurry to see that everything works.

We need to add more documentation and fix minor class implementation issues.