moved WINDOW functions to local file scope