Remove $.each

jQuery.each is slow, using while-loops instead