Small changes and fixes to encoding / decoding.