Fixed bug when 'sids' change while iterating