Moved loop counter as it wasn't being incremented when exceptions occurred.
Merge origin/master