Refactor if-else blocks in app delegate into functions