Fixed bug where only first iteration was used