modified the D matrix computation.