more robust source encoding detection