Improved thread lifecyvcle handling.