Fix write encoding