Add support for identities.
tidy up identity class, add tests.