Refactor the global mat as its own class.