added proper termination for cleanup threads