Changing global to matrix