Backport fix for encoding issue, close #255