correcting index of nodes in each separate function