refactoring AppDelegate