Tightened up the matching code