fixed threading bug