switched to iterative method