cleaned up the code for the matrix view