Added KeyboardInterrupt handling