fix threading bug