Added assertions and ExitThread calls.