Reworked function

Changed number of nodes into an argument