bug fix: incorrect buffer decreasing