refactoring for app delegate