Move startup logic and the creation of appstate.