Refactored AppDelegate