Various encoding fixes

Ticket: #5015