Create recursive function