wrote the main matching algorithm, but only returns 1 result