improve encoding detection