   (stock/entry id (metadata-str received command version certname)))
 
 (defn entry->cmdref [entry]
-  (let [[received-time-ms command version certname] (str/split (stock/entry-meta entry) #"_" 4)
-        received (-> received-time-ms
+  (let [{:keys [stamp command version certname]} (-> entry
+                                                     stock/entry-meta
+                                                     parse-metadata)
+        received (-> stamp
                      Long/parseLong
                      tcoerce/from-long
                      kitchensink/timestamp)]
-
     (map->CommandRef {:id (stock/entry-id entry)
                       :command command
                       :version (Long/parseLong version)

      (throw+ {:kind ::parse-error} e "Error parsing command"))))

(defn metadata-str [received command version certname]
  (format "%s_%s_%s_%s" (tcoerce/to-long received) command version certname))

(defrecord CommandRef [id command version certname received callback annotations delete?])


  (:require [stockpile :as stock]
            [clj-time.coerce :as tcoerce]
            [puppetlabs.puppetdb.cheshire :as json]
            [puppetlabs.puppetdb.command.constants :as constants]
            [clojure.string :as str :refer [re-quote-replacement]]
            [clj-time.core :as time]
            [puppetlabs.kitchensink.core :as kitchensink]
            [slingshot.slingshot :refer [throw+]]
            [clojure.core.async :as async]
            [clojure.core.async.impl.protocols :as async-protos]))

(def metadata-command-names
  (vals constants/command-names))

(defn stream->json [^InputStream stream]
  (try
