Handle exit more or less cleanly.