Small improvements to shutting down.
Merge.