Add encoding and decoding
Minor improvements
Start adding tests