Mostly reimplemented resizing + a few small optimizations