Fix bug in write().