cleaned up @Christian-B's charset parser code
removing old cruft
now folds character sets into the output