Better error handling for files