Fixed thread cleanup in case it was not started.