add convertEncoding function to code