Fix untyped field encoding, add tests