fixed bug in clean matrix