refactored window resize code