Fix encoding detection