Continued refactor and added integration tests.