 			++y
 		@context.putImageData @frame, 0, 0
 		localStorage.setItem("state", @editor.getValue())
-		console.log (+new Date) - t0 + "ms"
+		
+		console.log (+new Date) - t0 + "ms", 'reflect'
 	
 	scroll: =>
-		@scrollTop = $(window).scrollTop()
-		@scrollBottom = @scrollTop + @height
-		lines = @editor.lineCount()
-		end = Math.min(@height, lines)
-		first = @editor.coordsChar(x: null, y: @scrollTop).line
-		last = @editor.coordsChar(x: null, y: @scrollBottom).line + 1
-		y = 0
+		t0 = (+new Date)
+		
+		top = @top
+		bottom = @bottom
+		height = $(window).height()
+		scrollTop = $(window).scrollTop()
+		@top = @editor.coordsChar(x: null, y: scrollTop).line
+		@bottom = @editor.coordsChar(x: null, y: scrollTop + height).line + 1
+		y = Math.min(top, @top)
+		end = Math.max(bottom, @bottom)
 		while y < end
 			x = col = 0
 			while x < @width
-				ch = @editor.getLine(y).charAt(col)
+				ch = @editor.getLine(y)?.charAt(col)
 				if ch and /\t/.test(ch)
-					if y > first and y < last
+					if @top < y < @bottom
 						@setPixel x, y, 200, 225, 255, 125
 						@setPixel x + 1, y, 200, 225, 255, 125
 					else

				++col
			++y
		@context.putImageData @frame, 0, 0
		#if lines > @height
			#offset = -(first / lines * (lines - @height)) | 0
			#$("#scroll").css('top', offset + 'px') 
	
	downloadAs: (name) ->
		raw = @editor.getValue()

					else
						@setPixel x, y, 0, 0, 0, 255
				else
					if @top < y < @bottom
						@setPixel x, y, 200, 225, 255, 125
					else
						@setPixel x, y, 0, 0, 0, 0
