Refactor match-dependent functions to use generalized higher order funct...

...ion.