Refactor app delegate