Added try-except to catch KeyboardInterrupt during loop.