Refactor app initialization