                           ))))
 
 
-(defn start-client [host port {:keys [group read-ch internal-error-ch error-ch write-ch handlers] :as conf 
-                                 :or {group (NioEventLoopGroup.) 
+(defn start-client 
+  ([host port {:keys [group read-ch internal-error-ch error-ch write-ch handlers reconnect-count closed] :as conf 
+                                 :or {group (NioEventLoopGroup.)
+                                      reconnect-count (AtomicInteger. (int 0))
+                                      closed (AtomicBoolean. false)
                                       read-ch (chan 100) internal-error-ch (chan 100) error-ch (chan 100) write-ch (chan 100)}}]
   "Start a Client instance with read-ch, write-ch and internal-error-ch"
   (try

		          (if (instance? Stop v) nil ;if stop exit loop
		             (do 
                   (try 
                      (cond (instance? Reconnected v) (do (recur (:client v))) ;if reconnect recur with the new client
					             (instance? Pause v) (do (<! (timeout (:time v))) (recur local-client)) ;if pause, wait :time millis, then recur loop
					             :else
				                (do ;else write the value to the client channel
                           
						               (do-write local-client v false conf)))
                           (if (> (.get ^AtomicInteger (:reconnect-count local-client)) 0) (.set ^AtomicInteger (:reconnect-count local-client) 0))
                      
							        (catch Exception e (do ;send any exception to the internal-error-ch
								                            (error "!!!!! Error while writing " e)  
								                            (go (>! internal-error-ch [e nil]))

    (go 
      (loop [local-client client]
        (let [[v o] (<! internal-error-ch)
              reconnect-count (.get ^AtomicInteger (:reconnect-count local-client))
              ]
          (error "read error from internal-error-ch " v " reconnect count " reconnect-count)
          (prn "is closed " (:closed local-client) " hash " (hash (:closed local-client)))
          (if (> reconnect-count retry-limit) ;check reconnect count
             (do ;if the same connection has been reconnected too many times close
               (write-poison local-client)
               (try
                   (close-all local-client)
                   (catch Exception (.printStackTrace e)))
               
               (.set ^AtomicBoolean (:closed local-client) true)
               (go (>! error-ch [v o])) ;send the error channel
               
               )
             (do
		          (if (instance? Poison v)
