performance enhancements, then moved findLeaf into test loop