         (ido-enable-flex-matching smex-flex-matching)
         (ido-max-prospects 10)
         (minibuffer-completion-table choices))
-    (ido-completing-read (smex-prompt-with-prefix-arg) choices nil nil
-                         initial-input 'extended-command-history (car choices))))
+    (smex-extract-command-name
+     (ido-completing-read (smex-prompt-with-prefix-arg) choices nil nil
+                          initial-input 'extended-command-history (car choices)))))
 
 (defun smex-prompt-with-prefix-arg ()
   (if (not current-prefix-arg)

  (smex-detect-new-commands)
  (smex-rebuild-cache)
  (add-hook 'kill-emacs-hook 'smex-save-to-file)
  (setq smex-initialized-p t))

(defun smex-initialize-ido ()

  (setq smex-ido-cache (smex-convert-for-ido smex-cache)))

(defun smex-convert-for-ido (command-items)
  (mapcar (lambda (command-item)
            (let* ((command (car command-item))
                   (command-name (symbol-name command))
                   (keybinding
                    (gethash command smex-command-keybindings)))
              (if keybinding
                  (format "%s (%s)" command-name keybinding)
                command-name)))
          command-items))

(defun smex-restore-history ()
  "Rearranges `smex-cache' according to `smex-history'"
