Fix integration tests. Improve unit tests.