fix threading issues