Add the resizing handling method and refactoring.