more tweaks to encoding / decoding and tests