Minor main class refactoring and added integration tests for it.