subtantial rewrite of resizing logic, bugfixes