decoding fixes, and the corresponding tests.
WIP: more decoding. Known broken.
leverage os.path.
Pull from HG.