More refactoring on threads