Move the loopback code to a specific function.