refactor thread factory