Refactored AppDelegate.