added encoding detection support