fixing node counting function

The script now works.
There is still an issue with the calculation but it is theoretical