this implementation uses recursion.