fixed write bug