Revert "Write directly to the data array instead of temp buffer"

This reverts commit 02fa088ff1ee0033dad93a86abaa435c9743990d.