Improve SIGTERM handling. See issue #40