Bug fixes for write.