Thread refactoring