Moved code the invariant code out of the loop in updateTorrents