isLeaf() function