Refactor app creation into a factory pattern

This should make testing easier and it removes many of the import side-effects that were making life difficult.