Make exit nicely. And remove unused code.