Refactor resize event handler