Various encoding-related fixes