fixed computation of matrix