bugs in unsafeWrite