add buffer shrinking to free memory