added nonrecursive functionality