Fix failing integration test.
Refactor a bit the code.