works even window is loaded