refactored that mess of a Match function into something more OO