you could do active_thread_ids.uniq once outside / after the loop.