refactor out cyclic imports

Move over to the app-factory style of initialisation. This has the
advantage of reducing the number of magic global initialisations.