Fixed thread not joining correctly