Recursive implementation.