Added KeyboardInterrupt handler to terminate dispatcher; did some refactoring