final version of recursion exercise