creates tables for matching, matching function