Better handling of error on write