threads refactor