code to count nodes