Refactor waiting thread cleanup.
Refactor waiting thread removal.