Mostly fixed the matching algorithm Still needs lots of testing