completed matching function