replaced all usages of $.each() with a native js for loop