Large scale re-write

Refactored to better allow Android and other similar use cases to use
it.
Reformat
Make serialization work again