Add logic to auto detect file encoding

Fix style array index overflow issue, add name as Id.