exericse 1.37: fixed bug to iterative version