   ## Server Callbacks
 
   def init(:ok) do
-    # init the asset storage agent
-    Agent.start_link(fn ->
-      %{
-        block_cnt: (:rpc |> Gold.getblockcount!()) - 10
-       }
-    end, name: @agent_name)
     # init the Repo
     init(:retry, true)
   end
 
   defp init(:retry, log) do
     try do
-      {:ok, _} = :rpc |> Gold.getblockcount
+      # Check the connection
+      block_cnt = :rpc |> Gold.getblockcount!
       Logger.info("Explorer.Repo: RPC connection initialized (reload_interval: " <> Integer.to_string(reload_interval) <> ")")
+      # Init the asset storage agent (TODO: persistent storage)
+      Agent.start_link(fn ->
+        %{
+          low_cnt: block_cnt - 100,
+          high_cnt: block_cnt - 100
+         }
+      end, name: @agent_name)
+      # Init the task supervisor
+      Task.Supervisor.start_link(name: @tasksup_name)
+      # Initial blockchain parse (TODO: persistent storage)
       parse_new_blocks(1)
       {:ok, %{connected: true}}
     rescue

  alias BitcoinTool.Address
  alias Mercator.RPC

  defp reload_interval, do: 60*60*1000 # TODO from config

  @agent_name String.to_atom(Atom.to_string(__MODULE__) <> ".Agent")

  ## Client API


    Agent.update(@agent_name, &Map.put(&1, key, value))
  end

  defp parse_blocks!(low, high) do
    hash = :rpc |> Gold.getblockhash!(high)
    block = :rpc |> Gold.getblock!(hash)
    [block] |> parse_blocks!(low, high)
  end

  defp parse_blocks!(blocks, low, high) do
    [prev_block | _] = blocks
    block = :rpc |> Gold.getblock!(prev_block.previousblockhash)

    cnt = blocks |> Enum.count
    div = cnt/100
    if (Float.ceil(div) == div) do
      IO.puts cnt
    end

    block |> process_block

    unless (block.height == low) do
      [block | blocks] |> parse_blocks!(low, high)
    else
      [block | blocks]
    end
  end

  defp process_block(block) do
    task = @tasksup_name
    |> Task.Supervisor.async(fn () ->
      outputs = block.txns
      |> Enum.map(&(&1 |> RPC.gettransaction!))
      |> Enum.map(&(&1.outputs))
      |> List.flatten
      |> Enum.filter_map(
        fn(o) -> o.value > 0 end,
        fn(o) ->
          parsed = o |> Script.parse_address
          case parsed do
            {:ok, addr} -> %{address: Address.base58check(addr), value: o.value}
            other -> other
          end
        end)
      %{height: block.height, outputs: outputs}
    end)
  end

end
