partial implementation of match functions

problem: performance may not be efficient — 4 nested for loop may not
be good idea. Need to find a better way to perform this if we need to
take care of scalability