cr cleanup and optimization of isLeaf()