 
   def parse_proto(proto_path) do
     parsed = Protobuf.Parser.parse_files!([proto_path])
-    proto = %Proto{}
-    services = []
-    proto = Enum.reduce parsed, proto, fn(item, proto) ->
+    proto = Enum.reduce parsed, %Proto{}, fn(item, proto) ->
       case item do
         {:package, package} ->
           %{proto | package: to_string(package)}

          rpcs = Enum.map(rpcs, fn(rpc) -> Tuple.delete_at(rpc, 0) end)
          service_name = service_name |> to_string |> camelize
          service = %Proto.Service{name: service_name , rpcs: rpcs}
          %{proto | services: [service|services]}
        _ -> proto
      end
    end
    package = proto.package || Path.basename(proto_path, ".proto")
    %{proto | services: Enum.reverse(proto.services), package: package}
  end

  def top_mod(package) do
    package
    |> to_string
    |> String.split(".")

  end

  def generate(proto_path, out_path, opts) do
    proto = parse_proto(proto_path)
    assigns = [top_mod: top_mod(proto.package, proto_path, opts), proto_content: proto_content(proto_path, opts),
               proto: proto, proto_path: proto_path(proto_path, out_path, opts),
               use_proto_path: opts[:use_proto_path], service_prefix: service_prefix(proto.package) ]
    create_file file_path(proto_path, out_path), grpc_gen_template(assigns)
