Refactoring.

- Functions use local vars
- Each app install is contained in its own function
- HTTP status codes other than 200 result in the script aborting