updated recursive method