fix threading
refactor