 							}
 							if references.keys and references.keys.length > 0
 								references.keys.forEach (key) ->
-									if !(key in [null, undefined])
+									if key?
 										result.push({
 											caption: "\\#{commandName}{#{previousArgsCaption}#{key}#{closingBrace}"
 											value: "\\#{commandName}{#{previousArgs}#{key}#{closingBrace}"

					, 0
			if (
				change.action == "insert" and
				change.lines[0] in ["\\begin{}", "\\ref{}", "\\usepackage{}", "\\cite{}"]
			)
				setTimeout () =>
					@editor.execCommand("startAutocomplete")


			LabelsCompleter =
				getCompletions: (editor, session, pos, prefix, callback) ->
					{commandFragment, closingBrace} = Helpers.getContext(editor, pos)
					if commandFragment
						refMatch = commandFragment.match(/^~?\\([a-z]*ref){([^}]*, *)?(\w*)/)
						if refMatch
							[commandName, currentArg] = refMatch
							result = []
							if commandName != 'ref' # ref is in top 100 commands
								result.push {
