Added ability to kill oneself

Also cleaned up the code a little to allow the program to cleanly shut
down.