removes all for loops and replaces them by $.each