full iterative version added