Improve signal handling

Improve the way we deal with signals that might interrupt processing,
and clean up some of our shutdown logic at the same time.