recursive function fully working!