Fixed encoding bugs