select-application: aggressive refactoring