Placed window creation within a function

Window object cannot be initially set inside function. That is why there
is two lines of code