Adds an integration test, and fixes a few bugs.