Improve KeyboardInterrupt handling