Thread refactor