Fixed a bug where buffer may not be resized fully