completed recursive method