refactored thread creation block