Update encoding.py

Get encoding improved based on buriy's update