Minor corrections for write function