Update to isLeaf logic