refactors to use $.each