Modified build-automata-fn to return a function instead of defining one using defn