Manually catch SIGINT and SIGTERM signals and close gracefully. Fixes #40