fixed a bug in waiting for instances.