Fix iterator in for-loop
Improve formatting of code