Cleanup

Just some refactoring and cleanup.

* Pull out a `Formatter` interface.
* Better tests
* More idiomatic names: `root` => `DefaultNamespace`
* More reusability.