add some error handling on open/write