Added more consistency checks.
Misc changes.