Added file-encoding detection to handle non UTF-8 files