I was a bit lazy here. I should really encapsulate this in an inner function. The user should never pass the root argument.