App startup code, refactoring