Corrected the matrix calculation