improve encoding.cpp