fix if window is undefined