Added further character set handling to preview function to accommodate different incoming encodings.