@kelvin-chappell When you say difficult to read, do you mean the recursion? I was going to split it out into two different functions with repeated code (Like I say in the description), but decided to reuse the code instead.
Yes I shall have to make a unit test for this, but it won't happen until next year.