preliminary matching function