building the matrix