Refactor matching code.