refactor resize window function