Adding error handling around creating the buffer.