Refactoring for eliminating long-run thread