 	# model.applyOp 'doc', OPC
 	@applyOp = (docName, opData, callback) ->
 		p "applyOp #{docName} op #{i opData}"
+
 		# Its important that all ops are applied in order.
-		pendingOps[docName] ||= {busy:false, queue:[]}
-		pendingOps[docName].queue.push [opData, callback]
-		flushOps docName
+		queues[docName] ||= queue (opData, callback) -> applyOpInternal docName, opData, callback
+		queues[docName](opData, callback)
 	
 	# Perminantly deletes the specified document.
 	# If listeners are attached, they are removed.

p = -> #require('util').debug
i = -> #require('util').inspect

types = require '../types'
db = require './db'
Events = require('./events')

				# The op is up to date already. Apply and submit.
				submit()

	queues = {} # docName -> syncQueue

	# Apply an op to the specified document.
	# The callback is passed (error, applied version #)
