Refactoring + some integration tests