better handling of unspecified encodings, minor style improvements