Fix tests. Add tests. Fix bug found because of tests.