   end
 
   def install_update(url) do
-    prevent_double_installation!()
-    FarmbotCore.Logger.debug(3, "Downloading FBOS upgrade from #{url}")
-    params = {to_charlist(url), []}
+    try do
+      prevent_double_installation!()
+      download_update_file(url)
+      do_flash_firmware()
+    after
+      finalize_installation()
+    end
+  end
 
-    {:ok, :saved_to_file} = :httpc.request(:get, params, [], stream: @dl_path)
+  def finalize_installation() do
+    if has_artifacts?() do
+      clean_up()
+      FarmbotCore.Logger.debug(3, "Going down for reboot.")
+      FarmbotCeleryScript.SysCalls.reboot()
+    end
+  end
 
-    FarmbotCore.Logger.debug(
-      3,
-      "Finished downloading upgrade. Begin installation."
-    )
+  def clean_up() do
+    FarmbotCore.Logger.debug(3, "Cleaning up file artifacts.")
+    File.rm!(to_string(@dl_path))
+  end
+
+  def do_flash_firmware() do
+    msg = "Finished downloading upgrade. Begin installation."
+    FarmbotCore.Logger.debug(3, msg)
 
     path_string = to_string(@dl_path)
     args = ["-a", "-i", path_string, "-d", "/dev/mmcblk0", "-t", "upgrade"]
 
     {_, 0} = System.cmd("fwup", args)
+  end
 
-    FarmbotCore.Logger.debug(3, "Instalation complete. Cleaning up.")
-    File.rm!(path_string)
+  def download_update_file(url) do
+    FarmbotCore.Logger.debug(3, "Downloading FBOS upgrade from #{url}")
+    params = {to_charlist(url), []}
 
-    FarmbotCore.Logger.debug(3, "Going down for reboot.")
-
-    FarmbotCeleryScript.SysCalls.reboot()
+    {:ok, :saved_to_file} = :httpc.request(:get, params, [], stream: @dl_path)
   end
 
   def handle_http_response({:ok, {_status_line, _response_headers, body}}) do


    # Probably never returns?
    :ok
  end

  def get_target() do

  @dl_path '/root/upgrade.fw'
  @double_flash_error "A software update is already in progress. Please wait."

  def check_update() do
    get_target()
    |> download_meta_data()
