         rules (map #(keyword (get-in % [:rule])) grammar)
 
         ;; indices from paths to subsets of the lexicon
-        aux2lex (map-subset-by-path lexicon-for-generation [:synsem :aux])
-        pred2lex (map-subset-by-path lexicon-for-generation [:synsem :sem :pred])
-        cat2lex (map-subset-by-path lexicon-for-generation [:synsem :cat])
-
-        indices
-        (into {}
-              (map (fn [path]
-                     [path (map-subset-by-path lexicon-for-generation path)])
-                   [[:italiano :italiano]]))]
+        indices (create-indices lexicon-for-generation)]
         
     {:name "medium"
      :generate {:lexicon lexicon-for-generation}
      :grammar grammar
-     :index-fn (fn [spec]
-                 (do (log/debug (str "index-fn called with spec: " 
-                                    (strip-refs
-                                     (dissoc (strip-refs spec)
-                                             :dag_unify.core/serialized))))
-                     (log/debug (str "aux2lex: " (count
-                                                  (get aux2lex (get-in spec [:synsem :aux]
-                                                                       ::undefined)))))
-                     (log/debug (str "cat2lex: " (count
-                                                  (get cat2lex (get-in spec [:synsem :cat]
-                                                                       ::undefined)))))
-                     (log/debug (str "pred2lex: " (count
-                                                   (get pred2lex (get-in spec [:synsem :sem :pred]
-                                                                         ::undefined)))))
-                     (log/trace (str "aux2lex: " (clojure.string/join
-                                                  ","
-                                                  (sort (map #(fo %)
-                                                             (get aux2lex (get-in spec [:synsem :aux]
-                                                                                  ::undefined)))))))
-                     (log/trace (str "cat2lex: " (clojure.string/join
-                                                  ","
-                                                  (sort (map #(fo %)
-                                                             (get cat2lex (get-in spec [:synsem :cat]
-                                                                                  ::undefined)))))))
-                     (log/trace (str "pred2lex: " (clojure.string/join
-                                                   ","
-                                                   (sort (map #(fo %)
-                                                              (get pred2lex (get-in spec [:synsem :sem :pred]
-                                                                                    ::undefined)))))))
-                     (let [result
-                           (reduce intersection-with-identity
-                                   (filter #(not (empty? %))
-                                           (concat
-                                            (map (fn [path]
-                                                   (get (get indices path)
-                                                        (get-in spec path ::undefined)))
-                                                 [[:italiano :italiano]])
-                                            [(get pred2lex (get-in spec [:synsem :sem :pred] ::undefined))
-                                             (get aux2lex (get-in spec [:synsem :aux] ::undefined))
-                                             (get cat2lex (get-in spec [:synsem :cat] ::undefined))
-                                             ])))]
-                       (log/debug (str "indexed size returned: " (count result)))
-                       result)))
-                       
+     :index-fn (fn [spec] (lookup-spec spec indices))
      :language "it"
      :language-keyword :italiano
      :lexical-cache (atom (cache/fifo-cache-factory {} :threshold 1024))

    (log/debug (str "micro lexicon size:" (count (keys micro-lexicon))))
    (clojure.core/merge small
                        {:lexicon micro-lexicon})))

(defn medium []
  (deliver-lexicon)

       :lexicon lexicon
       :lexical-cache (atom (cache/fifo-cache-factory {} :threshold 1024))
       :rules rules
       :rule-map (zipmap rules grammar)}))

