Refactor for threads.