Improve SIGTERM handling. See issue #40

In response to #40