Added var to variables in for loops to avoid global variable errors in qunit