Added waith for stopping main thread