updated recursion solution