# Buggy code
def _start_cb(self, elems):
    """Initialize the elements and labels based on the context set."""
    if self._context is None:
        log.hints.debug("In _start_cb without context!")
        return

    if not elems:
        message.error("No elements found.")
        return

    strings = self._hint_strings(elems)
    log.hints.debug("hints: {}".format(", ".join(strings)))

    for elem, string in zip(elems, strings):
        label = HintLabel(elem, self._context)
        label.update_text("", string)
        self._context.all_labels.append(label)
        self._context.labels[string] = label

    keyparsers = objreg.get("keyparsers", scope="window", window=self._win_id)
    keyparser = keyparsers[usertypes.KeyMode.hint]
    keyparser.update_bindings(strings)

    message_bridge = objreg.get("message-bridge", scope="window", window=self._win_id)
    message_bridge.set_text(self._get_text())
    modeman.enter(self._win_id, usertypes.KeyMode.hint, "HintManager.start")

    if self._context.first:
        self._fire(strings[0])
        return
    # to make auto_follow == 'always' work
    self._handle_auto_follow()


# Traceback (AttributeError)
16:39:39 DEBUG    commands   command:run:486 command called: follow-hint ['-s', 'd']
16:39:39 DEBUG    commands   command:run:501 Calling qutebrowser.browser.hints.HintManager.follow_hint(<qutebrowser.browser.hints.HintManager object at 0x7f70c01191f8>, True, 'd')
16:39:39 ERROR    misc       crashsignal:exception_hook:216 Uncaught exception
Traceback (most recent call last):
File "/usr/lib64/python3.5/site-packages/qutebrowser/app.py", line 933, in eventFilter
return handler(event)
File "/usr/lib64/python3.5/site-packages/qutebrowser/app.py", line 906, in _handle_key_event
return man.handle_event(event)
File "/usr/lib64/python3.5/site-packages/qutebrowser/keyinput/modeman.py", line 335, in handle_event
return handler(event)
File "/usr/lib64/python3.5/site-packages/qutebrowser/keyinput/modeman.py", line 168, in _handle_keypress
match = parser.handle(event, dry_run=dry_run)
File "/usr/lib64/python3.5/site-packages/qutebrowser/keyinput/modeparsers.py", line 271, in handle
match = super().handle(e)
File "/usr/lib64/python3.5/site-packages/qutebrowser/keyinput/basekeyparser.py", line 182, in handle
self.execute(binding, count)
File "/usr/lib64/python3.5/site-packages/qutebrowser/keyinput/modeparsers.py", line 56, in execute
self._commandrunner.run(cmdstr, count)
File "/usr/lib64/python3.5/site-packages/qutebrowser/commands/runners.py", line 304, in run
result.cmd.run(self._win_id, args, count=count)
File "/usr/lib64/python3.5/site-packages/qutebrowser/commands/command.py", line 502, in run
self.handler(*posargs, **kwargs)
File "/usr/lib64/python3.5/site-packages/qutebrowser/browser/hints.py", line 926, in follow_hint
elif keystring not in self._context.labels:
AttributeError: 'NoneType' object has no attribute 'labels'

# Fixed code
def _start_cb(self, elems):
    """Initialize the elements and labels based on the context set."""
    if self._context is None:
        log.hints.debug("In _start_cb without context!")
        return

    if not elems:
        message.error("No elements found.")
        return

    # Because _start_cb is called asynchronously, it's possible that the
    # user switched to another tab or closed the tab/window. In that case
    # we should not start hinting.
    tabbed_browser = objreg.get(
        "tabbed-browser", default=None, scope="window", window=self._win_id
    )
    tab = tabbed_browser.widget.currentWidget()
    if tab.tab_id != self._tab_id:
        log.hints.debug(
            "Current tab changed ({} -> {}) before _start_cb is run.".format(
                self._tab_id, tab.tab_id
            )
        )
        return

    strings = self._hint_strings(elems)
    log.hints.debug("hints: {}".format(", ".join(strings)))

    for elem, string in zip(elems, strings):
        label = HintLabel(elem, self._context)
        label.update_text("", string)
        self._context.all_labels.append(label)
        self._context.labels[string] = label

    keyparsers = objreg.get("keyparsers", scope="window", window=self._win_id)
    keyparser = keyparsers[usertypes.KeyMode.hint]
    keyparser.update_bindings(strings)

    message_bridge = objreg.get("message-bridge", scope="window", window=self._win_id)
    message_bridge.set_text(self._get_text())
    modeman.enter(self._win_id, usertypes.KeyMode.hint, "HintManager.start")

    if self._context.first:
        self._fire(strings[0])
        return
    # to make auto_follow == 'always' work
    self._handle_auto_follow()