trying a better way of detecting file encoding