Fixed bug in which closing group left orphan tabs

The bug was caused by closing the tabs in the group while iterating over the list of tabs.  Closing a tab removes it from the list, so we were changing the list while iterating over it.  This caused some tabs to be skipped in iteration and not closed, and these were left as orphan tabs.