Root to leaf function