Writer performance improvements

Reduced memory allocations and increased performance of the writer by a
factor of 2.