Check that window is not null before using it