 
 						applyUpdate = (wrapper, newItems) ->
 							if angular.isArray newItems
-								ndx = wrapper.scope.$index
 								for newItem,i in newItems
 									if newItem == wrapper.scope[itemName]
 										keepIt = true;

							if pending.push(direction) == 1
								fetch(rid)

						insert = (index, item) ->
							itemScope = $scope.$new()
							itemScope[itemName] = item
							toBeAppended = index > first
							itemScope.$index = index
							itemScope.$index-- if toBeAppended
							wrapper =
								scope: itemScope

							linker itemScope, (clone) ->
								wrapper.element = clone
								# operations: 'append', 'prepend', 'remove', 'update', 'none'
								if toBeAppended
									wrapper.op = 'append'
									if index == next
										wrapper.doInsert = ->
											builder.append clone
											builder.bottomPadding(Math.max(0,builder.bottomPadding() - wrapper.element.outerHeight(true)))
											wrapper.op = 'none'
										buffer.push wrapper
									else
										wrapper.doInsert = ->
											buffer[index-first-1].element.after clone
											wrapper.op = 'none'
										buffer.splice index-first+1, 0, wrapper
								else
									wrapper.op = 'prepend'
									wrapper.doInsert = ->
										builder.prepend clone
										# an element is inserted at the top
										newHeight = builder.topPadding() - wrapper.element.outerHeight(true)
										# adjust padding to prevent it from visually pushing everything down
										if newHeight >= 0
											# if possible, reduce topPadding
											builder.topPadding(newHeight)
										else
											# if not, increment scrollTop
											viewport.scrollTop(viewport.scrollTop() + wrapper.element.outerHeight(true))
										wrapper.op = 'none'
									buffer.unshift wrapper

						adjustBuffer = (rid, finalize)->
							wrapper.doInsert() for wrapper in buffer when wrapper.op is 'append'
							wrapper.doInsert() for wrapper in buffer.slice(0).reverse() when wrapper.op is 'prepend'
							removeElement wrapper for wrapper in buffer.slice(0) when wrapper.op is 'remove'
						# We need the item bindings to be processed before we can do adjustment
							$timeout ->
								#log "top {actual=#{builder.topDataPos()} visible from=#{topVisiblePos()} bottom {visible through=#{bottomVisiblePos()} actual=#{builder.bottomDataPos()}}"
								if shouldLoadBottom()

										if result.length > 0
											clipBottom() if buffer.length
											for i in [result.length-1..0]
												--first
												insert result[i]
											#log "prepended: requested #{bufferSize} received #{result.length} buffer size #{buffer.length} first #{first} next #{next}"
										finalize rid

