various small fixes to encoding