Fixed bug in error handling in main that left a thread unterminated.