Improve encoding detection/conversion