better error handling for IOError