Clean up some buffer management code