Used $.each() instead of for()