Updated to allow changing number of nodes