bug in buffering code