Modifying query for matches