added table consistency checks and rollback function