Fixed write bug