update solution of problem 9.7, add recursive method