Remove use of window inside closure