some work to auto detect charset