Right encoding support - part 02

Almost obvious patches.

Need #3475 to work properly.