Fixing bugs in write path.