Change types into a proper class, add some better docs.
Add a bunch of tests for various type enc/dec, fix found bugs