Reading nodes and initializing the matrix