Added threading and exit waiting.