More refactoring cleanup + integration tests.