Move app instantiation to a function.