 
   ## Manifest handling
 
-  # Reads the manifest returning the results as tuples.
-  # The beam files are read, removed and stored in memory.
-  defp read_manifest(manifest, dest, keep_paths) do
-    initial = {[], []}
-
-    case File.read(manifest) do
-      {:ok, contents} ->
-        keep_paths = Enum.map(keep_paths, &(&1 <> "/"))
-        Enum.reduce String.split(contents, "\n"), initial, fn x, acc ->
-          read_manifest_entry(String.split(x, "\t"), acc, dest, keep_paths)
+  defp read_manifest(manifest) do
+    case :file.consult(manifest) do
+      {:ok, [{:version, @manifest_vsn}|t]} -> t
+      {:error, _} -> []
+    end
+  end
+
+  defp parse_manifest(manifest, keep_paths) do
+    Enum.reduce read_manifest(manifest), {[], []}, fn
+      {beam, module, source, deps, files}, {keep, skip} ->
+        entry = {beam, module, source, deps, files, nil}
+
+        if String.starts_with?(source, keep_paths) do
+          {[entry|keep], skip}
+        else
+          {keep, [entry|skip]}
         end
-      {:error, _} ->
-        initial
-    end
-  end
-
-  defp read_manifest_entry([_beam, module, source|deps], {keep, skip}, dest, keep_paths) do
-    {deps, files} =
-      case Enum.split_while(deps, &(&1 != "Elixir")) do
-        {deps, ["Elixir"|files]} -> {deps, files}
-        {deps, _} -> {deps, []}
-      end
-
-    # TODO: Notice we do not use beam from the file.
-    # From Elixir v1.2 onwards, we can start writing "1"
-    # instead of the beam file in write_manifest/2.
-    entry = {Path.join(dest, module <> ".beam"), module, source,
-             deps, files, nil}
-
-    if String.starts_with?(source, keep_paths) do
-      {[entry|keep], skip}
-    else
-      {keep, [entry|skip]}
-    end
-  end
-
-  defp read_manifest_entry(_, acc, _dest, _skip_paths) do
-    acc
-  end
-
-  # Writes the manifest separating entries by tabs.
+    end
+  end
+
   defp write_manifest(_manifest, []) do
     :ok
   end
 
   defp write_manifest(manifest, entries) do
-    lines = Enum.map(entries, fn
-      {beam, module, source, deps, files, binary} ->
+    File.mkdir_p!(Path.dirname(manifest))
+
+    File.open!(manifest, [:write], fn device ->
+      :io.format(device, "~p.~n", [{:version, @manifest_vsn}])
+
+      for {beam, module, source, deps, files, binary} <- entries do
         if binary, do: File.write!(beam, binary)
-        tail = deps ++ ["Elixir"] ++ files
-        [beam, module, source | tail] |> Enum.join("\t")
+        :io.format(device, "~p.~n", [{beam, module, source, deps, files}])
+      end
+
+      :ok
     end)
 
     # The Mix.Dep.Lock keeps all the project dependencies. Since Elixir
     # is a dependency itself, we need to touch the lock so the current
     # Elixir version, used to compile the files above, is properly stored.
     Mix.Dep.Lock.touch
-
-    File.mkdir_p!(Path.dirname(manifest))
-    File.write!(manifest, Enum.join(lines, "\n"))
   end
 end

                Path.type(relative) == :relative,
                do: relative

    Agent.cast pid, &:lists.keystore(beam, 1, &1, {beam, bin, source, deps, files, binary})
  end

  defp get_external_resources(module) do


  defp remove_stale_entries([{beam, module, source, _d, _f, _bin} = entry|t], changed, removed, acc) do
    if source in changed do
      _ = File.rm(beam)
      _ = :code.purge(module)
      _ = :code.delete(module)
      remove_stale_entries(t, changed, [module|removed], acc)
    else
      remove_stale_entries(t, changed, removed, [entry|acc])
