Second implementation, iteration