Refactor and add first working integration test.