added cleaning in D matrix