fix some error handling to be more fault tolerant.