 
     # Starts a server responsible for keeping track which files
     # were compiled and the dependencies between them.
-    {:ok, pid} = Agent.start_link(fn -> {modules, files, sources} end)
+    {:ok, pid} = Agent.start_link(fn -> {modules, sources} end)
     long_compilation_threshold = opts[:long_compilation_threshold] || 5
 
     try do

  ## Resolution

  defp update_stale_sources(sources, removed, changed) do
    Enum.reduce changed, Map.drop(sources, removed), &Map.put(&2, &1, [])
  end

  # This function receives the manifest entries and some source
  # files that have changed. It then, recursively, figures out
  # all the files that changed (via the module dependencies) and
  # return the non-changed entries and the removed sources.
  defp update_stale_entries(modules, files, [], stale) when stale == %{} do
    {modules, files, []}
  end

  defp update_stale_entries(modules, files, changed, stale) do
    removed = Enum.into(changed, %{}, &{&1, true})
    remove_stale_entries(modules, files, stale, removed)
  end

  defp remove_stale_entries(modules, files, old_stale, old_removed) do
    file_modules =
      Enum.reduce modules, %{}, fn module(source: source) = module, file_modules ->
        file = Enum.find(files, & file(&1, :file) == source)
        Map.update(file_modules, file, [module], &[module | &1])
      end

    {rest_modules, rest_files, new_stale, new_removed} =
      Enum.reduce file_modules, {[], [], old_stale, old_removed}, &remove_stale_entry/2

    if map_size(new_stale) > map_size(old_stale) or
       map_size(new_removed) > map_size(old_removed) do
      remove_stale_entries(rest_modules, rest_files, new_stale, new_removed)
    else
      {rest_modules, rest_files, Map.keys(new_removed)}
    end
  end

  defp remove_stale_entry({file, modules}, acc) do
    file(file: source, compile: compile, runtime: runtime) = file
    {rest_modules, rest_files, stale, removed} = acc

    cond do
      # If I changed in disk or have a compile time dependency
      # on something stale, I need to be recompiled.
      Map.has_key?(removed, source) or Enum.any?(compile, &Map.has_key?(stale, &1)) ->
        stale =
          Enum.reduce modules, stale, fn module(beam: beam, module: module), stale ->
            remove_and_purge(beam, module)

            Map.put(stale, module, true)
          end

        removed = Map.put(removed, source, true)
        {rest_modules, rest_files, stale, removed}

      # If I have a runtime time dependency on something stale,
      # I am stale too.
      Enum.any?(runtime, &Map.has_key?(stale, &1)) ->
        rest_modules = modules ++ rest_modules
        rest_files = [file | rest_files]
        stale = Enum.reduce(modules, stale, &Map.put(&2, &1, true))
        {rest_modules, rest_files, stale, removed}

      # Otherwise, we don't store it anywhere
      true ->
        {modules ++ rest_modules, [file | rest_files], stale, removed}
    end
  end



  defp parse_manifest(data, state) do
    Enum.reduce data, state, fn
      module() = module, {modules, sources} ->
        {[module | modules], sources}
      source() = source, {modules, sources} ->
        {modules, [source | sources]}
    end
  end

  defp write_manifest(manifest, [], []) do
    File.rm(manifest)
    :ok
  end

  defp write_manifest(manifest, modules, sources) do
    File.mkdir_p!(Path.dirname(manifest))

    File.open!(manifest, [:write], fn device ->
