Fix buffering

I wish I'd thought of a more functional way to do this. Maybe later.