better character encoding detection