Several refactorings and lots of integration tests