Refactor app setup function
Refactor app setup function

Split app setup into smaller functions and
add documentation for a couple of non-obvious caveats.

robertknight/passcards,robertknight/passcards,robertknight/passcards,robertknight/passcards