Added functional test for loopback device. Fix loopback bug.