fix DTD invariant checking
bugfix
still fixing obvious bugs
still fixing tests