refactor thread