A collection of small patches to fix some incorrect failure paths and generally tidy up the corresponding teardown code, mostly relating to contexts, and in particular the global default context that's created at startup. These should make subsequent reorganisation of other startup/teardown code easier and safer.