Fix small bug in retrieving leaves