better error handling on writes