updated to include alternative encoding detections