Added a clever check to verify that the node is a leaf.