Fix logic error in FiniteDomain.retain.
Refactor domain implementations.
Refactor domains and add a few tests.