refactor app delegate