cleaned the code in matrix.py