Changed the resize function, refactoring pt2