Leaf scanning code