Fix multi threading issues