implementing charset detection