Improve window resize handling