Numerous bug fixes from integration tests.