added detectEncoding