improved serial and tcp loopback