Fix for threads being terminated correctly.