remove duplicate code for getting the global matrix