fixed a few multi threading issues