trying to replace $.each() with for
fixed callback bug