Improve code reuse in check_match::specialize()

I've been working around these parts of code and it seems like it could use a bit of a refactor. This is the first step.