added window verification due to script error when window is null