Implement encode and decode

Finish!