Add some comments and tidy up the KeyboardInterrupt handling, even though it's only used during testing.