rework decoder and encoder slightly to be a little more sane