 (defn create
   [^CuratorFramework client path & {:keys [data] :as opts}]
   (try 
-    (let [cr (.. client 
+    (let [cr ^SetDataBuilder (.. client 
                  create 
                  (withMode (create-mode opts)))]
       (if data 
-        (.forPath cr path data)
-        (.forPath cr path)))
+        (.forPath ^SetDataBuilder cr path data)
+        (.forPath ^SetDataBuilder cr path)))
     (catch org.apache.zookeeper.KeeperException$NodeExistsException e
       false)))
 

                 creatingParentsIfNeeded 
                 (withMode (create-mode opts)))]
      (if data 
        (.forPath cr path data)
        (.forPath cr path)))
    (catch org.apache.zookeeper.KeeperException$NodeExistsException e
      false) ))


  "Deletes the given node if it exists. Otherwise returns false."
  [^CuratorFramework client path]
  (try
    (.forPath ^DeleteBuilder (.delete client) path )
    (catch KeeperException$NoNodeException e false)))

(defn children 
  ([^CuratorFramework client path & {:keys [watcher]}]
   (let [children-builder ^GetChildrenBuilder (.getChildren client)]
     (if watcher 
       (.forPath ^GetChildrenBuilder (.usingWatcher children-builder ^Watcher (make-watcher watcher)) path)
       (.forPath ^GetChildrenBuilder children-builder path)))))

(defn data [^CuratorFramework client path]
  (let [stat ^Stat (Stat.)
        data (.forPath ^GetDataBuilder (.storingStatIn ^GetDataBuilder (.getData client) stat) path)] 
    {:data data
     :stat (stat-to-map stat)}))

(defn set-data [^CuratorFramework client path data version]
  (.forPath ^SetDataBuilder (.withVersion ^SetDataBuilder (.setData client) 
                                          version) 
            path 
            data))

(defn exists [^CuratorFramework client path & {:keys [watcher]}]
  (stat-to-map 
    (let [builder ^ExistsBuilder (.. client checkExists)]
      (if watcher
        (.forPath ^ExistsBuilder (.usingWatcher builder ^Watcher (make-watcher watcher)) path)
        (.forPath builder path))))) 
