replace $.each with native for each loops