A useful reference could be to look at the "pick all" condition or maybe even the "pick by uid" condition.
For verifying the instances still exist:
One way that would work could be to find each instance in their object type's list of instances.
Another idea that could be investigated would be If instances somehow were marked as dead. If it wasn't then you'd need to check if the uid was the same. If it wasn't it would be a recycled instance.
Just some ideas. I'm not near a dev PC to try any out ATM.