maybe pass in the buffer with reference, and re-allocate it if needed.