fixed threading issues