Functionize

* Creates functions that do the encoding/decoding.
* Also some small functions to for abstraction