-handle exception during call of "windowList.IndexOf"
-handling of empty string copied
- code changes based on comments from nagappanal