Ported encode / decode methods from pre 0.1.0 tagged code