Autoupgrade + small refactoring