Improve file related error handling