Refactored GetData and TryOptimisticWrite into only one call of GetNextBatch

The operation is more atomic on the file implementation side +
simplicity in rest