Refactor match model.

Extract and rename methods. Add clarifying comments.
Merge branch 'refactor-match'