Fixed a few bugs and tests.
Some work on refactoring existentials and contracts.