by Bedunkevich S V - updated encoding