 		onChange: (change) ->
 			cursorPosition = @editor.getCursorPosition()
 			end = change.end
-			context = Helpers.getContext(@editor, end)
-			{lineUpToCursor, commandFragment} = context
+			{lineUpToCursor, commandFragment} = Helpers.getContext(@editor, end)
 			if lineUpToCursor.match(/.*%.*/)
 				return
 			lastCharIsBackslash = lineUpToCursor.slice(-1) == "\\"

			references = @$scope.$root._references
			ReferencesCompleter =
				getCompletions: (editor, session, pos, prefix, callback) ->
					context = Helpers.getContext(editor, pos)
					{commandFragment, closingBrace} = context
					if commandFragment
						citeMatch = commandFragment.match(
							/^~?\\([a-z]*cite[a-z]*(?:\[.*])?){([^}]*, *)?(\w*)/
						)
						if citeMatch
							commandName = citeMatch[1]
							previousArgs = citeMatch[2]
							currentArg = citeMatch[3]
							if previousArgs == undefined
								previousArgs = ""
							previousArgsCaption = if previousArgs.length > 8 then "…," else previousArgs
							result = []


			GraphicsCompleter =
				getCompletions: (editor, session, pos, prefix, callback) ->
					{commandFragment, closingBrace} = Helpers.getContext(editor, pos)
					if commandFragment
						match = commandFragment.match(/^~?\\(includegraphics(?:\[.*])?){([^}]*, *)?(\w*)/)
						if match
							[commandName, _, currentArg] = match
							graphicsPaths = Preamble.getGraphicsPaths()
							result = []
							for graphic in Graphics.getGraphicsFiles()
