Improving IO error handling