Deal with various text encodings