Improved looping.

Improved looping