check for matches before looping through them