Replace inlined JS code with CS code that compiles down to for-loops
Rename local var for readability