Added tree content checking to distance method