Added waitForThreadCompletion