changed while function to _.each function