changes $.each to normal for loops