fix scoping issue in for loops

Copying the context object each time is creating scoping issues in the for loops.  By maintaining the reference to context, variables that are created and / or modified inside the loop still exist outside the loop as well.