by Bedunkevich S V - updated encoding 2