Changed Loop implementation.

Nested loops partially working.