Cleaned up shutdown sequence.

Now the discovery and organization threads shutdown cleanly even if
an import is in progress (and we ask before shutting down in the
middle of an import).