Better way to calculate matrix fields