use $.each instead of indexed for loop