Updated encoding sniffing algorithm