Moved the invariant code out of the loop in updateTorrents()