fixing some threading issues