   def msg(self, subject, sid, reply_queue, what) do
     send self, {:command, {:msg, subject, sid, reply_queue, what}}
   end
-  def handle_info({:command, cmd}, %{sock: socket} = state) do
+  def handle_info({:command, cmd}, state) do
     pack = Nats.Parser.encode(cmd)
-    case :gen_tcp.send(socket, pack) do  # :ssl.send(socket, pack) do # 
+    case :gen_tcp.send(state.sock, pack) do
+      # case :ssl.send(state.socket, pack) do
       :ok -> :ok # IO.puts "sent #{inspect(pack)}..."
       {:error, :closed} -> IO.puts "socket closed: ignoring for NOW!!"
       oops -> IO.puts "NATS send unexpected result: #{inspect(oops)}"
     end
     {:noreply, state}
   end
-  def handle_info({:tcp_closed, sock}, state) do
-    IO.puts ("tcp_closed: #{inspect(sock)}")
+  def handle_info({:tcp_closed, _sock}, state) do { :noreply, state } end
+  def handle_info({:tcp_error, _sock, _reason}, state) do
     { :noreply, state }
   end
-  def handle_info({:tcp_error, sock, reason}, state) do
-    IO.puts ("tcp_closed: #{inspect(sock)}: #{reason}")
-    { :noreply, state }
-  end
-  def handle_info({:tcp_passive, sock}, state) do
-    IO.puts ("tcp_passive: #{inspect(sock)}")
-    { :noreply, state }
-  end
-  def handle_info({:tcp, _sock, data}, state) do
-#    IO.puts ("tcp: #{inspect(data)}")
-    val = Nats.Parser.parse(state.ps, data)
-#    IO.puts "received NATS message: #{inspect(val)}"
-    case val do
-      {:ok, msg, rest, nps} -> handle_packet(%{state | ps: nps}, msg)
-      other -> nats_err(state,
-                        "received a bad parser result: #{inspect(other)}")
+  def handle_info({:tcp_passive, _sock}, state) do { :noreply, state } end
+  def handle_info({:tcp, _sock, data}, state) do handle_packet(state, data) end
+  def handle_info({:ssl, _sock, data}, state) do handle_packet(state, data) end
+  defp handle_packet(state, <<>>) do {:noreply, state} end
+  defp handle_packet(state, packet) do
+    pres = Nats.Parser.parse(state.ps, packet)
+#    IO.puts "received NATS packet: #{inspect(pres)}; raw: #{inspect(packet)}"
+    case pres do
+      {:ok, msg, rest, nps} ->
+        {:noreply, ns } = handle_packet1(%{state | ps: nps}, msg)
+        handle_packet(ns, rest)
+      other -> nats_err(state, "invalid parser result: #{inspect(other)}")
     end
   end
-  def handle_info({:ssl, _sock, data}, state) do
-#    IO.puts ("tcp: #{inspect(data)}")
-    val = Nats.Parser.parse(state.ps, data)
-#    IO.puts "received NATS message: #{inspect(val)}"
-    case val do
-      {:ok, msg, rest, nps} -> handle_packet(%{state | ps: nps}, msg)
-      other -> nats_err(state,
-                        "received a bad parser result: #{inspect(other)}")
-    end
-  end
-  defp handle_packet(state, msg) do
+  defp handle_packet1(state, msg) do
     case msg do
       {:info, json} -> nats_info(state, json)
       {:connect, json} -> nats_connect(state, json)

                         host: @default_host, port: @default_port,
                         socket_opts: [:binary, active: true]},
                 ps: nil}
  def start_link do
    start_link(@default_host, @default_port)
  end

  def start_link(host, port \\ @default_port) do
    state = @start_state
    state = %{state | opts: %{state.opts | host: host, port: port}}

      _ -> nats_err(state, "received bad NATS verb: -> #{inspect(msg)}")
    end
  end
  defp nats_err(state, what) do
    IO.puts ("received nats_err: #{inspect(what)}")
    {:noreply, %{state | state: :error}}
  end
  defp check_auth(_json_received, json_to_send, _auth_opts) do
    # FIXME: jam: check auth_required, etc.
    {:noreply, json_to_send }
  end
  defp nats_info(state = %{state: :want_info}, json) do
    # IO.puts "NATS: received INFO: #{inspect(json)}"
