corrected matching scheme and added loopback