Added countNodes function