re-apply encoding fixes that got lost in merge