Changed line 36 to use an iterator

This should remove bounds checking and speed up overall execution of the code.