Added lots of buffering code