resize, and other refactoring