Lots of (mostly internal) api cleanup
Some added tests
Documentation.
Meta