Committing working version up to and including decode. Encode is next.