Restructured to reduce writing to buffers