Initialization with variable number of nodes