Changed resizing algorithm