improve instance handling
Merge pull request #4045 from qunox/instancehadling

improve instance handling