refactored thread joining