added comprehensive set matching function