Fix window size detection code