Refactor: replace for() to $.each()