some tweaks on encoding