add some functions to check instances existence.
some more checks.
make simpler logic for the script.
fix tests.