completed recursive func