refactoring window resize function.