implemented recursive method