Apply encoding patch from steverandy