replaced jQuery .each with simple for(;;)