recursive implementation

recursive implementation