Fix write bug