rework thread handling