figuring out iterative version