Refactored handling of window resize event