reorganise the matrix