Merge pull request #2111 from spnethw/improved-automatic-encoding-detection