Refactor a lot of table error recovery code.