fixed foreach issue when collection array is emptied & recreated