Adds match types to global definitions.
More separation of concerns; huge rewrite...