Recursive to itterative